“And needed not that any should testify of man: for he knew what was in man.”
He did not need any testimony about mankind, for he knew what was in each person — the closing statement of the temple-clearing episode serves as a theological hinge between chapter 2 and the Nicodemus encounter that follows. The verb knew (ginosko) here carries the weight of divine omniscience rather than mere perception: Jesus' knowledge of the human heart is presented as comprehensive and unsought. The contrast with the crowds who believed in his name because of the signs (2:23) is deliberate — the signs produce a shallow, wonder-based response, but Jesus does not entrust himself to sign-faith because he perceives its fragility. The verse prepares the reader for Nicodemus, who arrives as a representative figure of the sign-impressed believer, coming at night with a faith still partly in shadow. John's Gospel will repeatedly return to the theme that Jesus knows what people are — the Samaritan woman (4:17-18), the crowd seeking bread (6:26), Judas (6:70-71) — establishing divine knowledge as the basis of his relational discernment.
Church Fathers on John 2:25
The Evangelist has related above what our Lord did on his way to Jerusalem; now He relates how others were affected towards Him at Jerusalem; Now when He was in Jerusalem at the Passover, in the feast day, many believed in His Name, when they saw the miracles which He did.
But how was it that many believed in Him from seeing His miracles? for he seems to have performed not supernatural works at Jerusalem, except we suppose Scripture to have passed them over. May not however the act of His making a scourge of small cords, and driving all out of the temple, be reckoned a miracle?
Those had been wiser disciples, however, who were brought to Christ not by His miracles, but by His doctrine. For it is the duller sort who are attracted by miracles; the more rational are convinced by prophecy, or doctrine. And therefore it follows, But Jesus did not commit Himself to them.