Just my thoughts about this:
Psalm 51 is a psalm of repentance by David, after he went to Bath Sheba. And, he repents as only King David can.
Because of that - and that's where quoting this Psalom is off imho - he truly repents from the depth of his heart and soul, not making any excuses at all for sinning, humbling himself and - in verse 7 - telling it as it is, about the sin nature, not making an excuse of it, but acknowledging that he knows his condition as one born in sin, HOWEVER also had divine wisdom enough to know not to fall in that temptation and sin....
Here is the entire text of the Psalm with Rashi's comment on the verse quoted:
Tehillim - Psalms - Chapter 51Chapter 511. For the conductor, a song of David.
2. When Nathan the prophet came to him when he went to Bath-sheba.
3. Be gracious to me, O God, according to Your kindness; according to Your great mercies, erase my transgressions.
4. Wash me thoroughly of my iniquity, and purify me of my sin.
5. For I know my transgressions, and my sin is always before me.
6.
Against You alone have I sinned, and I have done what is evil in Your sight, in order that You be justified in Your conduct, and right in Your judgment.
7. Behold, with iniquity I was formed, and with sin my mother conceived me. Behold, with iniquity I was formed: Now how could I not sin when the main part of my creation was through coitus, the source of many iniquities?
Another explanation: The main part of my creation is from a male and a female, both of whom are full of iniquity. There are many midrashim to this verse, but they do not fit the context of the psalm.
conceived me: Heb. יחמתני,
an expression of heat, as (Gen. 30:38): “And they came into heat (ויחמנה) when they came to drink.”
8. Behold, You desired that truth be in the hidden places,
and in the concealed part You teach me wisdom. 9.
Purify me with a hyssop, and I will become pure;
wash me,
and I will become whiter than snow.
10. Make me hear joy and gladness; let the bones that You crushed exult.
11. Hide Your countenance from my sins, and
erase all my iniquities.
12.
Create for me a pure heart, O God, and renew a steadfast spirit within me. 13. Do not cast me away from before You,
and do not take Your holy spirit from me. 14. Restore to me the joy of Your
salvation, and let a noble spirit support me.
15.
I will teach transgressors Your ways, and sinners will return to You. 16. Save me from blood, O God, the God of my salvation; let my tongue sing praises of Your charity.
17. O Lord, You shall open my lips, and my mouth will recite Your praise.
18. For You do not wish a sacrifice, or I should give it; You do not desire a burnt offering.
19.
The sacrifices of God are a broken spirit; O God, You will not despise a broken and crushed heart. 20. With Your will, do good to Zion; build the walls of Jerusalem.
21.
Then You will desire sacrifices of righteousness, a burnt offering and a whole offering; then they will offer up bulls on Your altar.
**Also, along with your question, King David's flaws - because he had some serious ones, yet was a man after God's own heart - were very public, everybody knew about his weaknesses, and when he sinned, his sinning was very public too. However, so was his repenting! He was the king, but when the prophet spoke, David repented, publicly, went and sat himself down, still king, but before God, humbling himself and repenting...
That attitude of the heart is what is often missing.... Maybe we need to go back and have repentance services.... Well, maybe that's another thread..