This psalm of David paints picture of him being in a court of law, as the defendant, where he is pleading his case before the judge which is God. What’s interesting is that although David appears to be the defendant he consistently calls for the punishment for his opponents.
The psalm begins with an appeal for judgment on his enemies. His appeal is that they be judged on his own, not God’s terms. This is interesting because when David was faced with making deciding whether to be judged by men or God he chose God because he knew that God is merciful and man is not.
2 Samuel 24:11-14 (NKJV)11 Now when David arose in the morning, the word of the LORD came to the prophet Gad, David's seer, saying,12 "Go and tell David, 'Thus says the LORD: "I offer you three things; choose one of them for yourself, that I may do it to you." ' "13 So Gad came to David and told him; and he said to him, "Shall seven years of famine come to you in your land? Or shall you flee three months before your enemies, while they pursue you? Or shall there be three days' plague in your land? Now consider and see what answer I should take back to Him who sent me."14 And David said to Gad, "I am in great distress. Please let us fall into the hand of the LORD, for His mercies are great; but do not let me fall into the hand of man." (emphasis mine)
He expresses his resentment by asking that his enemies be completely defeated, discredited, and caught in their own pitfalls. He ends this section at verse 10 with a vow that he will really rejoice in the Lord.
In the next section of the psalm beginning with verse 11 David now identifies his enemies as former friends that have now turned on him. They lied on and mocked him, mocked him, while he only returned good for their evil. He also ends this section at verse 18 with a vow that he will publicly praise God if God will only deliver him.
David again appeals for judgement. He first pleads that his enemies back off and stop taunting and spreading evil lies about him. Then he asks for final judgement with his enemies now getting the same treatment that they gave him. He closes this section, and the psalm with a vow of thanksgiving.