you are wrong, he punished David and his unborn child for Adultery with Bathsheba and the murder of Uriah.
Ecclesiastes 4:1-3
Then I returned and considered all the oppression that is done under the sun:
and look! The tears of the oppressed, but they have no comforter— on the side of their oppressors [there is] power, but they have no comforter.
Therefore I praised the dead who were already dead, more than the living who are still alive.
Yet, better than both [is he] who has never existed, Who has not seen the evil work that is done under the sun.
.. and David's sin was removed, in conjunction with the death of a child who was born, a son who was given.