2 Samuel 12:14
"But because by doing this you have made the enemies of the Lord show utter contempt, the son born to you will die."
While David's son died as a result of David's sin (see 2 Sam 11 and 12:1-25 for the full story), the effects ended there; he would not be punished for his father's sin in the afterlife (Ezek 18:19-20). 2 Samuel 12:14 implies that the death of David's son was meant to be a lesson to others who were disobeying God. When word got around that David had committed adultery and murder, some Israelites would probably have said to themselves, "If the king can do those things and not face any consequences, why can't I?" People in other nations who heard of it wouldn't see it as reason to follow Israel's God, but if they heard of the consequences they would know that God saw and dealt with David's sin. It's possible that his son's death also ensured that David's repentance was permanent, for he would always remember his son and the effects of his adultery.
Other responses (offsite)