I will wash mine hands in innoceney; so will I compass thine altar, O Lord. This seems to be the key-note of the psalm. If not a necessary, it is at any rate a probable, exegesis, that David composed this psalm on an occasion when he was about to offer a sacrifice of praise and thanksgiving to God for some mercy recently vouchsafed him (Psalms 26:7).
Before offering, he feels the necessity of doing spiritually that which the priest' who officiated would have to do ceremonially (Exodus 30:17-21)—to "wash his hands in innocency, and so to go to God's altar."
His self-justification from Psalms 26:1 to Psalms 26:5 has had for its object to clear him from guilt.