There are two matters here that should not be confused in reading Ps 51:12:
- David's "joy of God's salvation", ie, the assurance of personal salvation under the covenant promises
- David's punishment, or more accurately, the disastrous consequences of David's actions which are clearly laid out - David would loose four of his sons to death by unnatural causes: (1) the son born to Bathsheba, 2 Sam 12:18; (2) Amnon the heir to the throne, 2 Sam 13; (3) Absalom the next heir to the throne, 2 Sam 18:14, 15; (4) Adonijah the next heir to the throne, 1 Kings 2:23-25.
However, there is good evidence that David enjoyed the joy of God's salvation as explicitly recorded in his Psalm of praise to God at the end of his life, 2 Sam 22 and 2 Sam 23:1-7 (see below)
APPENDIX - 2 Sam 23:1-7 (for completeness only). See also 2 Sam 22.
These are the last words of David:
“The oracle of David son of Jesse, the oracle of the man raised on
high, the one anointed by the God of Jacob, and the sweet psalmist of
Israel:
2 The Spirit of the LORD spoke through me; His word was on my tongue.
3 The God of Israel spoke; the Rock of Israel said to me, ‘He who rules the people with justice, who rules in the fear of God,
4 is like the light of the morning at sunrise of a cloudless dawn, the glistening after the rain on the sprouting grass of the earth.’
5 Is not my house right with God? For He has established with me an everlasting covenant, ordered and secured in every part. Will He
not bring about my full salvation and my every desire?
6 But the worthless are all like thorns raked aside, for they can never be gathered by hand.
7 The man who touches them must be armed with iron or with the shaft of a spear. The fire burns them to ashes in the place where they
lie.”