King David's punishment by the prophet Nathan follows David's sins of adultery with Bathsheba and the murder of her husband Uriah. See 2 Samuel 11.
David's position, as God's chosen and anointed king of Israel, makes these sins extra serious. David not only sets a bad example for his people, but also gives the enemies reason to blaspheme the name of the LORD. God has always been with David and blessed him, but despite this, David now goes against His will and commandments.
The prophet Nathan comes to David's palace and presents a case to him. The king sometimes acts as judge.
After Nathan tells the story about a rich and a poor man, David becomes angry with the rich man and pronounces judgment on him, invoking God's name. Then Nathan's story turns out to be a prophecy in the form of a parable; the 'rich man' in the story refers to David himself: “You are that man!”
Nathan then addresses David in God's Name, accusing him of being ungrateful, unfaithful and disobedient, and tells him what God's punishment for his sins will be. The sins were done in secret, but the punishment for sin will follow in public.
Davids reaction shows he is genuinely and deeply aware of his guilt:
“Then David said to Nathan, “I have sinned against the LORD.” (Verse 13)
David deserved the death penalty, but God is merciful to him. There will be consequences for his sins: the sword will never depart from the house of David. Also, the child that Bathsheba bears will die. Some interpreters see the mention of the fourfold compensation as a reference to the four children of David who died: the first child of Bathsheba, Amnon, Absalom and Adonijah.
Psalm 51 is the penitential psalm that expresses David's repentance:
1 ‘Have mercy on me, O God,
according to your steadfast love;
according to your abundant mercy blot out my transgressions.
2 Wash me thoroughly from my iniquity,
and cleanse me from my sin!
3 For I know my transgressions,
and my sin is ever before me.
4 Against you, you only, have I sinned
and done what is evil in your sight,
so that you may be justified in your words and blameless in your judgment’.
….Etcetera.
King David was in many ways a prefiguration of the Son of David, King Jesus, the Messiah of Israel. The LORD was with David, and his reign was righteous in many respects. Yet he also turns out to be a sinful and fallible man, unlike the Messiah, Jesus:
2 Corinthians 5 verse 19 to 21:
19 ‘that is, in Christ God was reconciling the world to himself, not counting their trespasses against them, and entrusting to us the message of reconciliation. 20 Therefore, we are ambassadors for Christ, God making his appeal through us. We implore you on behalf of Christ, be reconciled to God. 21 For our sake he made him to be sin who knew no sin, so that in him we might become the righteousness of God.’