Here David expresses the joy of forgiveness. God had forgiven him for the sins he had committed against Bathsheba and Uriah (2 Samuel 11–12). Paul quoted these verses in Romans 4:7, 8 and showed that we can have this joyous experience of forgiveness through faith in Christ.
(Source: Life Application Bible)
1 Of David. A maskil. Blessed is he whose transgressions are forgiven, whose sins are covered.
2 Blessed is the man whose sin the LORD does not count against him and in whose spirit is no deceit.
3 When I kept silent, my bones wasted away through my groaning all day long.
4 For day and night your hand was heavy upon me; my strength was sapped as in the heat of summer. Selah
5 Then I acknowledged my sin to you and did not cover up my iniquity. I said, “I will confess my transgressions to the LORD”– and you forgave the guilt of my sin. Selah
6 Therefore let everyone who is godly pray to you while you may be found; surely when the mighty waters rise, they will not reach him.
7 You are my hiding place; you will protect me from trouble and surround me with songs of deliverance. Selah
8 I will instruct you and teach you in the way you should go; I will counsel you and watch over you.
9 Do not be like the horse or the mule, which have no understanding but must be controlled by bit and bridle or they will not come to you.
10 Many are the woes of the wicked, but the Lord’s unfailing love surrounds the man who trusts in him.
11 Rejoice in the LORD and be glad, you righteous; sing, all you who are upright in heart!