Our sin breaks our fellowship with God. David realizes that before he ever committed adultery with Bathsheba, he committed spiritual adultery against God. Why did he need her? Why was he willing to murder his own friend for her? It is because before David ever sinned against Bathsheba and Uriah, he lost the joy of his salvation. That is why he asks for the joy to be restored [Psalm 51:12].
”—Rick Gamache, Whiter Than Snow
We sin because we forget God’s steadfast love and abundant mercy. When we are not ravished by him, we forget the superior pleasures that there are in God and give ourselves to the inferior pleasures of sin. And this is why David says, “Against you God, you only have I sinned.” He goes deep with his confession because he knows repentance is the way back to fellowship with God.