As we open to 2 Samuel 15, we have entered the consequence years of David’s[1] life. So even though David is beloved of the Lord, he still has to face the consequences, just like believers in the New Testament, who are also beloved of the Lord, have to face the consequences of our sins.
Every event from 2 Samuel 11 onward reflects in some way the results of those moments, when David was blinded by his sinful desires and acted rebelliously against God’s clear standards. After David sinned in so many ways surrounding his adultery, he tried to hide his sin, and did quite well, for quite a while.
Then, confronted by words from God’s prophet, David repents (a change of mind that leads to a change of behavior); David confesses (saying the same things about his sin that God says); and David forsakes his sin (turning in contrition and disgust from what offends God), and then experiences full, complete and endless forgiveness.