Matthew Henry's commentary frames this verse within a larger song of praise for God's deliverance. David's statement about his "righteousness" and "cleanness" is not a claim of sinless perfection, but a declaration that God has rewarded his faithful trust and integrity. It's a celebration of God vindicating him in the face of his enemies.