David knew that it was because of his sin with Bathsheba as the prophet Nathan had told him: “Now therefore (because of his sin) the sword shall never depart from your house, because you have despised me and have taken the wife of Uriah the Hittite to be your wife” (See 2 Samuel 12:7–15). God disciplined David like a father disciplines a son (2 Samuel 7:12–15; Psalm 89:29–33). And David bows under God’s judgment. You find the story in 2 Samuel 15:1–37.
1 O LORD, how many are my foes! Many are rising against me;