2 Samuel 12:18
And it came to pass on the seventh day, that the child died. And the servants of David feared to tell him that the child was dead: for they said, Behold, while the child was yet alive, we spake unto him, and he would not hearken unto our voice: how will he then vex himself, if we tell him that the child is dead?
The seventh day on which the child died belongs to the account of David's adultery with Bathsheba and murder of Uriah, in which Uriah carried his own death order from David to Joab to set him in the forefront of the hottest battle and withdraw from him so he would be smitten by the children of Ammon, which Joab obeyed. David had been firm while keeping God's Word, but turning from its teaching led to his fall and damaged his reputation. Although the Lord forgave David after his sincere repentance, he was still punished for his transgression in that the child died.
That death was the first stroke of the retribution that David himself had declared just. It stands as one consequence of David's sin and the retribution that follows when God's will is violated. While the child was still alive, David pleaded for its life and mourned over his sick child with fasting and deep humiliation, putting off his royal robes and crown and lying night after night upon the earth in heart-broken grief, refusing to be raised up, as he interceded for the innocent child suffering for his guilt.
He persevered in pleading so long as the child was spared because humiliation and repentance had often turned aside judgments pronounced upon persons or cities, since God is swift to pardon and send peace. When the child died, David quietly submitted to God's decree, rose from the ground and stopped mourning over him. Though grieving, he was not without comfort as he trusted in God's mercy.