I acknowledged my sin to You, and my iniquity I have not hidden. I said, “I will confess my transgressions to the LORD,” and You forgave the iniquity of my sin. Selah.
In Psalm 32 David contrasts the agony of guilt (verses 4-5) with the joy of forgiveness. When he finally stopped trying to cover up his adultery with Bathsheba and murder of Uriah, he poured out his heart to God in repentance.
Though Jesus Christ had not yet come to die in our place for our sins, God considers those things that will be as if they already are (Romans 4:17). So He could cover David’s sins with the blood of Christ and forgive him, just as He is willing to forgive us today.