“Vindicate me, O Lord, for I have walked in my integrity, and I have trusted in the Lord without wavering. Prove me, O Lord, and try me; test my heart and my mind. For your steadfast love is before my eyes, and I walk in your faithfulness.” -Psalm 26:1–3
David seems to have been falsely accused. There is not any specific occasion to which the psalm itself points. But this is not, by any means, a rare occasion for a monarch with political enemies. This could be any number of occasions from Saul to Absalom. The point is not in the occasion, however, but in the content of David’s prayer.
It is addressed to the Lord and made in the imperative voice, Vindicate me! David gives the reasons he deserves to be vindicated before his enemies as having led a life of general moral integrity (cf. NIV “a blameless life”) and has unwaveringly trusted the Lord (i.e. looked to the Lord as his refuge and hope and not turned to idols).
He then pleads using legal or courtly language for the Lord to examine the evidence—prove me, try me, test me. Specifically, he requests the Lord would examine what others cannot see—his heart and his mind—recalling to the Lord that he has kept the Lord’s steadfast love (cf. KJV, “lovingkindness”; NIV, “unfailing love”) as the center of his mental and emotional focus.
He has done as he had been instructed in the Law as a boy in Israel (i.e., Shema):
““Hear, O Israel: The Lord our God, the Lord is one. You shall love the Lord your God with all your heart and with all your soul and with all your might. And these words that I command you today shall be on your heart. You shall teach them diligently to your children, and shall talk of them when you sit in your house, and when you walk by the way, and when you lie down, and when you rise. You shall bind them as a sign on your hand, and they shall be as frontlets between your eyes. You shall write them on the doorposts of your house and on your gates.” -Deuteronomy 6:4–9
This command is what the Lord taught the disciples was the key to understanding all the Law and Prophets.
“And he said to him, “You shall love the Lord your God with all your heart and with all your soul and with all your mind. This is the great and first commandment. And a second is like it: You shall love your neighbor as yourself. On these two commandments depend all the Law and the Prophets.”” -Matthew 22:37–40