Could you please explain II Samuel 12:14? It seems that the child died because of what David did. But the Bible says that a child shall not die for the sins of the father.
"The soul who sins shall die. The son shall not bear the guilt of the father, nor the father bear the guilt of the son. The righteousness of the righteous shall be upon himself, and the wickedness of the wicked shall be upon himself" (Ezekiel 18:20).
A child is not guilty of his father's sins. The child will not die eternally because he had sinful parents, but this does not mean that physical death may not come upon a child because a parent is sinful. We read at times of some poor child who died from abuse, whose intoxicated parent crashed his car with children inside, or whose angry parent killed his spouse and his children. The child's death was not due to the child's sins but due to the sin of others. For that matter, the physical death of anyone does not tell you why that particular person died. It is a mistake to attribute all troubles to personal sins (a topic of the book of Job).
Yet, when David committed adultery with Bathsheba and then tried to cover it up with a murder, he was told that one consequence was that the child conceived by Bathsheba would die, even though David personally was forgiven of his sins. "So David said to Nathan, "I have sinned against the LORD." And Nathan said to David, "The LORD also has put away your sin; you shall not die. However, because by this deed you have given great occasion to the enemies of the LORD to blaspheme, the child also who is born to you shall surely die" (II Samuel 12:13-14). God refused to allow David to "profit" from his sins by allowing the son conceived in sin to live. The reason is that if the child lived, it would cause sinners to slander God's reputation due to the circumstances in which this child was conceived.
It was David and Bathsheba's second son, Solomon, who became the next king after David. David had other, older sons, but each proved to be unsuitable for rule. Consider that if the child had lived, he would likely have been the next king of Israel and in the lineage of the Messiah. God, who knows the future decided that this could not be allowed. It was a consequence of David's sin that wasn't immediately apparent.
Of course, the child had no sins being too young to break any law. In essense God granted the child entrance into heaven without having to suffer in this world. That is why David said, after the child died, "While the child was alive, I fasted and wept; for I said, 'Who can tell whether the LORD will be gracious to me, that the child may live?' But now he is dead; why should I fast? Can I bring him back again? I shall go to him, but he shall not return to me" (II Samuel 12:22-23).