The voice is explained when he says, Jesus answered. First, he explains the voice; secondly, he mentions the answer given by the people (v 34); and thirdly, our Lord's answer (v 35). He does two things about the first: first he mentions the reason for the voice; and secondly, he adds its meaning (v 31).
It should be noted in regard to the first that they had said, An angel has spoken to him. Now an angel speaks by revealing something that will profit the one to whom he speaks, as is clear in Revelation (ch 1) and in Ezekiel (ch 1). And so to show that he did not need this voice or any revelat...ion from an angel, our Lord says, This voice has come for your sake, not for mine, that is, it has not come to instruct me. For this voice mentioned nothing he did not know before, because "in him are hid all the treasures of wisdom and of knowledge" (Col 2:2), so that he knew all that the Father knew. But it has come for your sake, that is, for your instruction. From this we can understand that many things relating to Christ were, in God's plan, allowed to take place not because Christ needed them, but for our sakes: "For whatever was written in former days was written for our instruction" (Rom 15:4).
Source: Commentary on John