The idea of King David's baby being stricken ill and killed by God is a huge stumbling block to many would-be believers. Before discussing the matter let's review the situation first:
REVIEW OF THE SITUATION
To begin with, King David was considered to be very dear to God (Acts 13:22) and the Lord continued to be with David (1 Chronicles 11:9). David was given the Royal Messianic line that became the human ancestry of Jesus Christ, as shown by the line of descendants given at Matthew 1:6-16.
Starting with 2 Samuel Chapter 11 :
While David was reigning as king he fell into a moment of human weakness: One night, as he walked along his rooftop, he spied beautiful Bath-Sheba washing herself. He allowed his feelings of lust to overtake him and he slept with her (vs. 2-4) in spite of the fact that he was already a married man(1 Samuel 18:27, 30:5, 2 Samuel 3:5), and she was already married to Uriah, one of David's soldiers (vs. 3, 11). This tryst resulted in Bath-Sheba's pregnancy (vs. 5). David, in an attempt to cover it up, called for Uriah to return to his home for a few days hoping the couple would become intimate during this time (then he and Bath-Sheba could pretend the pregnancy belonged to Uriah instead of David). Uriah felt it would be unethical to sleep with his wife while the other soldiers were still on the battlefield so he refused to go home (vs. 6-13). Because David's ruse failed he plotted to murder Uriah -- he wrote a letter to the chief of the army, unwittingly delivered by Uriah himself, instructing that Uriah was to be abandoned on the battlefield to be killed. The plot succeeded, after which David married Bath-Sheba. Later, Bath-Sheba gave birth to David's baby boy (vs. 14-27).
Going into 2 Samuel chapter 12:
Soon after the baby was born God sent His prophet, Nathan, to rebuke King David for this string of sins he committed (lust, adultery, deception, and murder). David was wholeheartedly repentant for the actions he took, therefore God spared his life. However, God told him that although he was forgiven, he would still have to suffer the consequences for all his actions (vs. 1-13). One of those consequences including losing his newborn son (vs. 14)
For one week, the baby lay gravely ill. During this time, David fasted and prayed, hoping that God would change His mind and spare the child. However, at the end of the seven day period the baby died (vs. 15-18). And this is where people get upset:
How could God deign to kill an innocent baby?!
This is a tough question resulting from a tough situation. The only way to tackle such a difficult topic is to take it piece by piece:
The verse at 2 Samuel 12:14 Clearly states that David's sins in relation to Bath-Sheba would give occasion for God's enemies to blaspheme God (some versions use the word “contempt”). God had already made it clear that profaning His Holy Name is a serious sin deserving of death (Leviticus 24:16). It was also made clear in the Ten Commandments that anyone who abuses God's name was to be held guilty (Deuteronomy 5:11). David was aware of these Godly laws, as revealed in his words at Psalms 40:8, in which he said: "I delight to do thy will, O my God: yea, thy law is within my heart. " (KJV); therefore David couldn't claim ignorance of these things.
Now, David was the chosen anointed king handpicked by God Himself (1 Samuel 16:1-13, 2 Samuel 2:4, 10-11). Being God's chosen King he had a serious responsibility as a leader of God's people. This Bath-Sheba/Uriah situation, however, showed great disrespect for God's blessings (2 Samuel 12:8-9), contempt for God's laws, and made a mockery of the God-chosen kingship, resulting in profaning God's Holy Name. This is why the whole affair would give opportunity for blasphemy against Him.
This baby was the physical manifestation of David's disrespect, contempt, and mockery (ie blasphemy) against God. For as long as this baby existed the blasphemy against God would continue to exist. And, as we've seen earlier, David was quite cognizant of God's standards and knew that blasphemy could not be tolerated. God did not put this baby into this predicament, it was David who did this. This is why the death of the baby falls squarely on David's shoulders, not God's.
THE TEN COMMANDMENTS
There is also the matter of how many of the Ten Commandments David broke when he committed this string of sins. The first thing he did was covet his neighbor's wife (Exodus 20:17). Since coveting is the same as idolatry (Colossians 3:5), David also broke that commandment too (Exodus 20:3). Since idolatry requires an idol of some sort (in this case, Bath-Sheba's body), that commandment was also broken (Exodus 20:4-5). The next thing he did was commit adultery with his neighbor's wife (Exodus 20:14). Considering that adultery is tantamount to thievery (Psalms 50:18), he also broke the commandment against stealing (Exodus 20: 15) (2 Samuel 12:9). After this, he attempted to deceive by trying to cover up his paternity of the resulting child (Exodus 20:16). Lastly, he committed the sin of murder when his other plans failed (Exodus 20:13). All of this sin, scandal, and murder would have been a complete dishonour to his family, especially to the parents who raised him -- thus he also broke the commandment regarding the honouring of one's parents as well (Exodus 20:12).
So let's count this up:
1. Covetousness -- He lusted after another man's wife.
This means that in total, David's actions broke eight of the Ten Commandments in this one situation. David was God's chosen leader for the Israelite nation -- therefore this brazen disregard for so many of the Ten Commandments over one incident was not something to take lightly. Unfortunately, the baby was the physical proof of all these sins. God's pure Holiness cannot tolerate such a filthy stain on the leadership. This reflects back to the profanity against God's Holy Name; this stain needed to be removed.
Again, David caused this situation for the baby, not God.
Beyond the sullying of God's Holiness, beyond the breaking of most of the commandments, there is also the fact that the royal human ancestry of Jesus Christ was to come only through the line of David (Isaiah 11:10, Matthew 1:6-16). Since Bath-Sheba was still married to Uriah when David impregnated her, the baby would have been legally recognized to be of the house of Uriah in the Israelite culture. Think about it: Bath-Sheba surely gave birth long before her ninth month of marriage to David, thus people would have realized she conceived during her marriage to Uriah, thus the people would have considered this baby to be the child of Uriah. This would mean that the baby would have inherited Uriah's estate and holdings even though David sired him. On top of this, since the Messianic line was supposed to come through David, and not Uriah, this was making more of a mess of things regarding the legal paternity of the child. Imagine the inevitable confusion that would occur when it came to deciding who ascends the throne, who inherits Davids holdings, and who would be listed in the human ancestral line of Jesus Christ.
Note, also, that the Bible continues to speak of Bath-Sheba as the "wife of Uriah" while the child remained alive, even though David had already married her (2 Samuel 12:15). It wasn't until after the child was dead that Scripture refers to her as the wife of David (2 Samuel 12:24) as all legal connection to Uriah was then completely dissolved.
Realize that this wasn't just an ordinary incident of an adulterous liaison resulting in pregnancy; this particular baby whom David fathered had unwantingly become an intruder into the Royal Messianic line; and such an intruder could not be allowed to remain because the royal lineage must remain pure. God's plan could not be obstructed as the entire future of mankind was at stake – in order for God's plan to succeed, this situation needed to be removed for the good of all mankind. Again, it was David who thrust the baby into this situation, not God.
WHERE IS THE BABY NOW?
Although this baby boy was a casualty of David's blasphemy this doesn't mean this baby was eternally damned. Note that God could have damned the baby by ending the pregnancy at any time as He had no obligation to let the baby be born.*
And this is where God's love is found in all this mess:
God allowed the pregnancy to come to full term so that the baby could have a full week of life. By allowing that baby to live, even for such a brief amount of time, that baby was eligible to be covered under Christ's blood when Christ was sacrificed centuries later. In other words, even though that baby boy was the embodiment of blasphemy, God recognized his innocence and saved him through Christ's blood anyway. God's love is that beautiful. Hallelujah, and Amen.
We can't let surface impressions jeopardize our relationship with God, as Satan would love to paint God as a cruel Master. However, when we look past the surface we see that the cruelty actually lies with the actions of David and Bath-Sheba, whose selfish actions caused two innocent deaths, profaned God's Holy Name, and nearly broke the Royal Messianic Lineage. And in spite of the blasphemy made manifest in the baby, God still saw fit to give the baby opportunity for Salvation through Christ's blood. Please think carefully about these matters before dismissing our Awesome Creator as a worthless God.