One prominent view of Ps 82:6 has long been that the passage refers to YHWH’s divine council, the spirits that the nations wrongly worship as gods. Other passages in the OT do indeed suggest such imagery.
In the context of Ps 82, however, it applies most directly to human rulers. (Spiritual powers are behind the earthly powers, as becomes clear in Dan 10:13, 20 and in the New Testament, so in the end the approaches are complementary. But here I will deal just with the immediate sense in context.)
Here YHWH’s council consists of rulers (Ps 82:1) who judge unjustly (82:2). Ancient Near Eastern ethics in general, and certainly biblical ethics, invited rulers to avoid partiality and to protect the weak—though outside of Israel, legal customs usually favored the elites. Instead of defending the weak and the orphans, those without defenders, these rulers show partiality to the wicked (82:2-4).
Many ancient Near Eastern rulers considered themselves divine, sons of their nations’ chief deities. So God challenges them (along with the spirits behind them): “So: you are ‘gods, children of the Most High’! Rather: you will die like mortal humans, and fall like any of the princes” (82:6-7). The psalmist pleads for God to judge the earth, bringing righteous justice to the nations (82:8). This is a prayer for justice, against arrogant kings.
The principle has a message for all of us. God is not with the proud or the powerful who wrong others. God is with the socially weak, the politically and legally vulnerable. Even when justice in this world seems a long way off, we look to the righteous God to establish justice. God teaches us the way of justice so we can seek it, and he is our ultimate defender.