This sin mentioned in Psalms refers to original sin. David was born with a sinful nature, just as all of us are. Each human that is born is born with a twisted nature that leads them right into sin. Though we are not responsible for it being there, we are responsible for it remaining there and following its dictates. Jesus died to redeem from the acts of sin and the nature of sin. His blood can cleanse from sins committed and from the defilement of sin.
The two verses you quoted are unrelated when it comes to the relationship of a married man and women. Sin is not the sex act. However, when sanctified, Spirit filled parents conceive a child, that child will be born sinful. Why? The sin of Adam, human depravity, needs the atonement applied to the soul.
Psalm 51:5 does not imply that David's parents were committing adultery, they were already married. David had alot of older brothers.