The poet of Psalm 31 thus entreats this astonishingly righteous God to put that righteousness in play on the poet's behalf, and "deliver me." Just like Sodom, that notoriously wicked place, could have been saved by the existence of only one righteous man—Lot, presumably—so this psalmist asks YHWH for the same possibility. Deliver me, the poet cries, because you, O YHWH, are above all things righteous, much more than fair in your dealings with your people. Why, if YHWH is not righteous, what hope can there be for any human righteousness?
And now we can see why the poet sought YHWH's divine shelter in the first place. In YHWH shame will never attach itself to me; in YHWH's righteousness I will always be delivered, not always protected from harm, but always delivered.
And perhaps now you may catch a glimpse of the raw power and great comfort of these old poems. Psalm 31:1 clings to me still, just as I cling to my God who is my shelter and fortress.