Howbeit, because by this deed thou hast given great occasion to the enemies of the LORD to blaspheme, the child also that is born unto thee shall surely die.
- II Samuel 12:14
When Nathan confronted King David with the facts of the king's affair with Bathsheba and the killing of her husband Uriah, he stated in verse 13, The LORD also hath put away thy sin; thou shalt not die.
So, the obvious question is how the death of the child would in any way improve the situation. To answer the question, we need to consider the circumstances of the child's conception and a relevant declaration that God had made.
The baby was conceived as a result of an adulterous affair between David and Bathsheba, so the child was illegitimate and isn't referred to as their son. God had stated in Deuteronomy 23:2,
A bastard shall not enter into the congregation of the LORD; even to his tenth generation shall he not enter into the congregation of the LORD.
Since the child couldn't be considered a member of the congregation of God, he certainly wouldn't have been qualified to occupy the throne.
Consider a situation where David's first child from the woman he loved would grow up in the king's house and not be allowed to be king after David's death. Not only would the enemies of Israel ridicule the child, but David would have a constant reminder of his sin of adultery and the child would have to live with the stigma for which he could in no way be held responsible. So, God took the child in mercy before he could have any understanding of his plight.
When David was old and preparing to die, he removed any doubt that he would have wanted to be succeeded on the throne by the first son that he and Bathsheba produced. In I Kings 1:5, we can read that Adonijah the son of Haggith tried to ascend to the throne without the blessing of his father. Then, in verse 30 of the same chapter, David spoke to Bathsheba,
Even as I sware unto thee by the LORD God of Israel, saying, Assuredly Solomon thy son shall reign after me, and he shall sit upon my throne in my stead; even so will I certainly do this day.
The Child Shall Surely Die (cont)
By keeping in mind the facts of this case, we can understand why, in Psalm 51:5, David wrote:
Behold, I was shapen in iniquity; and in sin did my mother conceive me.
David was, of course, a legitimate son of Jesse, but he was responsible for the lack of legal status of the first child that Bathsheba bore for him and therefore responsible for the death of the child. So, with the words of that verse, David took on himself, figuratively speaking, the curse that the child bore. And, this leads us to see a picture of one aspect of Christ's death.
Since God states several times in Ezekiel 18 that the soul that sins shall die, we would have difficulty thinking of a way that an innocent child could die under condemnation. But, that is exactly what happened in the case of the unnamed child of David. The child certainly was innocent, because he couldn't even comprehend the meanings of right and wrong. So, his death because of David's sin demonstrates God's providence in carrying out the penalty for our sins on the innocent Christ. The representation is not perfect, of course, but the Bible contains many accounts of human situations that imperfectly, but dramatically, show forth the works of God in Christ.
Nathan had told David that God had taken away his sin and we can therefore see another aspect of Christ's suffering as God The Son. As David poetically appropriated the child's stigma in the words of Psalm 51:5, God judicially took on himself our sins and paid the penalty of spiritual death in the person of his son. As more than one Bible scholar has observed, we can understand the force of Isaiah 53:11 by reading it as He shall see of the travail of his (own) soul, and shall be satisfied:...
David's unnamed child lived only a few days and died under condemnation to give us a picture of The Lord's death. King Solomon reigned for many years and represents Christ The King that will reign forever after he returns. The King had to die; long live The King.