Peter Pett's Commentary on the Bible
Psalms 26 - Introduction
It should be considered that this Psalm could never have been written unless it had been preceded by Psalms 25. It was only once the question of forgiveness had been settled that the Psalmist could speak like this. For in this Psalm he approaches God with the confidence of a forgiven sinner.
Heading.
‘A Psalm of David.'
In this Psalm the Psalmist testifies to YHWH that he has responded to YHWH's covenant love and trustworthiness with a life of integrity and obedience, and he brings his life openly to God and calls on God to give him a religious check up. He is not afraid of this because he has already prepared himself by putting right all that was wrong in his life and seeking forgiveness (‘washing his hands in innocency'). He can also declare that he has not kept bad company, whether it be religiously devious, or openly sinful, and can therefore approach God to worship Him in innocency, which he does joyously because he loves His house and the place where His glory dwells. It is on these grounds that he looks to YHWH for long life so that he might continue to worship Him.