English Basic Explanation - Chapter 26
David begins this Psalm by confidently declaring his readiness and willingness to stand judgment before God. He avows his faith and trust in God, his refusal to participate in the schemes and machinations of evil men, and his love for the Mikdash. Rather then joining the company and ploys of the wicked, he has chosen instead the company of the Kohanim and Levi'im in the Temple, preferring to draw spiritual inspiration and express gratitude to God rather than win the favor and friendship of sinners (see Radak and Ibn Ezra, verse 8).
David's intent in this affirmation is not arrogance or vain triumphalism, but rather to pray that he not be included in the fate of the wicked, as he beseeches in verse 9. He has firmly rejected their company and behavior, and should therefore be spared the punishment that God will ultimately visit upon them. David thus begins this Psalm by asking God to judge him, which Rashi explains (based on the Midrash) as a request that he be judged in contrast to the wicked. He feels confident that his firm rejection of sin and corruption renders him worthy to escape the calamities that will befall the perpetrators of evil.
This Psalm thus underscores the importance of choosing the right friends, colleagues and role models. If we wish for God to judge us favorably, to include us among the righteous, then we must ensure to fully identify with the righteous and follow their example. Rather than placing ourselves in the company of corrupt sinners and trying to win their respect and friendship, we must instead strive to join the company of those who are seriously committed to Torah, so that we can learn from their example and be deserving of a judgment similar to theirs.