Reconsidering this question, I wish to amend my answer.
Paul testified before the men of Israel in Acts chap. 13,
"And when he had removed him, he raised up unto them David to be their king; to whom also he gave their testimony, and said, I have found David the son of Jesse, a man after mine own heart, which shall fulfil all my will.
23 Of this man's seed hath God according to his promise raised unto Israel a Saviour, Jesus:" (Acts `3:22-23, KJV)
God did not have David killed because David obeyed God. David immediately repented when Nathan confronted him.
The genealogy of Christ was always through the line of the faithful, and though David sinned against God, he returned to YHVH repenting (Psa. 32, 61, etc). But, David did the will of the Father, which was why God chose David to replace Saul.
"13 And Samuel said to Saul, Thou hast done foolishly: thou hast not kept the commandment of the Lord thy God, which he commanded thee: for now would the Lord have established thy kingdom upon Israel for ever.
14 But now thy kingdom shall not continue: the Lord hath sought him a man after his own heart, and the Lord hath commanded him to be captain over his people, because thou hast not kept that which the Lord commanded thee." (1 Sam. 13:13-14, KJV)
God would have used Saul, if Saul had obeyed the Father's commands. Whereas David did continue, even after his sins to do the will of the Father.
And so, God made David king over Israel.
"... Thus saith the Lord God of Israel, I anointed thee king over Israel, ..." (2 Sam. 12:7, KJV)
The punishment was worse than death because of the public shame. Losing face in the Middle Eastern and Asian societies is still to this day why many commit suicide.
2 Sam 12:9-12,
"9 Wherefore hast thou despised the commandment of the Lord, to do evil in his sight? thou hast killed Uriah the Hittite with the sword, and hast taken his wife to be thy wife, and hast slain him with the sword of the children of Ammon.
10 Now therefore the sword shall never depart from thine house; because thou hast despised me, and hast taken the wife of Uriah the Hittite to be thy wife.
11 Thus saith the Lord, Behold, I will raise up evil against thee out of thine own house, and I will take thy wives before thine eyes, and give them unto thy neighbour, and he shall lie with thy wives in the sight of this sun.
12 For thou didst it secretly: but I will do this thing before all Israel, and before the sun." (KJV)
To have this shame paraded publicly was a punishment worse than death for David. He would never again have peace in his house as his own sons would strive against him, and be a cause for further shame. We see in the next chapter that David's son Amnon raped his half-sister Tamar, which then causes such anger in his brother Absalom to bring him to murder Amnon.
The child was a fruit of the sin, and by taking that away from David God increased the punishment. The child's death was loss to David and Bathsheba, but the child was an innocent and therefore taken to Paradise. The baby suffered a little while, but only a few days before being comforted in Abraham's bosom. (Luke 16:19-31). But, David would regret his loss all the days of his life.
Considering how there would be no more peace in David's house, that brother was about to murder brother, only God knew what might have later happened to the child which might have been an eventual death anyway. By taking the child early, God may have been preventing an even greater tragedy later on.
David's public shame further caused the people to lose respect. His sons saw their father's sins and then emulated him. Sins have consequences, and though David asked for and received forgiveness (2 Sam. 12:13) doesn't mean that the human condition was not affected. Sin travels by example and usually from the top down to the bottom of society.
When people see those in high positions of authority behave badly and appear to get away with it, some will then reason in their hearts that "if he can do it, then I can". But, sin always affects others and causes death and mayhem to multiply.
David, as king used his power and authority to take Bathsheba from Uriah, and ultimately kill Uriah. Amnon used deceit and violence to take his half-sister, which ultimately resulted in fratricide by Absalom as David did not punish Amnon for his sins (2 Sam 13:24-31)
The consequences of the sins continue on as in the next chapters Absalom's hatred of his father plays out in usurpation and insurrection. Sin originates in the heart of man (Mark 7:21), but even though God will forgive us when we repent, sin travels on. We reap what we sow.
"7 Be not deceived; God is not mocked: for whatsoever a man soweth, that shall he also reap. 8 For he that soweth to his flesh shall of the flesh reap corruption; but he that soweth to the Spirit shall of the Spirit reap life everlasting." (Gal. 6:7-8, KJV)
However, there are many in the line of the Messiah who sinned, but their faith over came those sins.
"10 Many sorrows shall be to the wicked: but he that trusteth in the Lord, mercy shall compass him about." (Psa. 32:10, KJV)
God always chose the line of the faithful to carry out His plans. Which was why God chose Solomon over Adonijah to succeed David.
1 Chron. 28:5-7,
"5 And of all my sons, (for the Lord hath given me many sons,) he hath chosen Solomon my son to sit upon the throne of the kingdom of the Lord over Israel.
6 And he said unto me, Solomon thy son, he shall build my house and my courts: for I have chosen him to be my son, and I will be his father.
7 Moreover I will establish his kingdom for ever, if he be constant to do my commandments and my judgments, as at this day." (KJV)
(Bold emphasis is mine.)