Here our Lord defends himself against the charge of blasphemy. First, he gives his defense; secondly, he shows them the truth (v 37). He defends himself by divine authority, and so first, he mentions the authority of Scripture; secondly, he explains its meaning; and thirdly, he draws his conclusion.
The Evangelist says, Jesus answered them: Is it not written in your law (in Psalm 82:6): I said, you are gods? Here we should note that "law" is understood in three ways in Scripture. Sometimes it is taken in a general sense for the entire Old Testament, containing the five books of Moses, the pro...phets and the hagiographies. This is the way in your law is understood here, meaning in the Old Testament. For this quotation is from the psalms which are referred to as the law because the entire Old Testament is considered to have the authority of law. Sometimes "law" is understood as distinct from the prophets, psalms, and the hagiographies; this is the way Luke uses it in "Everything written about me in the law of Moses and the prophets and the psalms must be fulfilled" (Lk 24:44). Again, at other times it is distinguished from the prophets. In this sense the psalms and the other books of the Old Testament, other than the Pentateuch, are included within the prophets, on the ground that the Old Testament was produced by a prophetic spirit. This is the way it is understood in Matthew: "On these two commandments depend all the law and the prophets" (Matt 23:40).
The word "God" is also used in three senses. Sometimes it signifies the divine nature itself, and then it is used only in the singular: "Hear, O Israel: The Lord our God is one Lord" (Deut 6:4). At other times it is taken in a denominative sense: in this way idols are called gods: "All the gods of the peoples are idols" (Ps 96:5). And sometimes someone is called a god because of a certain participation in divinity, or in some sublime power divinely infused. In this way, even judges are called gods in Scripture: "If the thief is not known, the owner of the house shall be brought to the gods," that is, to the judges (Ex 22:8); "You shall not speak ill of the gods," that is, of the rulers (Ex 22:28). This is the way the word "god" is taken here, when he says, I said, you are gods, i.e., you share in some divine power superior to the human.
Source: Commentary on John