The baby was not conceived in a relationship blessed by God. This is one of the mysteries of marriage and is taught in the bible, from the first union of Adam and Eve, down through every couple that brings about the Plan of Salvation, whether it is Abraham and Sarah, Isaac and Rebekah, Jacob and Leah, to David, the first annointed King. God is a partner in the marriage and this marriage was not holy. Once David was married to Bath-Sheba, then God joined the union and brought Solomon, David's son, and the ancestor of Jesus.
I believe most Protestants deny marriage as a Mystery (i.e. Sacrament), so this is new to me. But nevertheless, the sin was that of David and his adulterous lover, not of his son. If God were to kill every offspirng of adulterous relationships, the earth would be a lot smaller, I am sure. God is a lot more merciful than that!