2 Samuel 12, David's son, and justice 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. Nevertheless, because by this deed you have utterly scorned the
  Lord, the child who is born to you shall die.” Then Nathan went to his
  house.


I've been trying to wrap my head around this part of scripture for a while now. How can a just God kill an innocent child for the sins of David? Most of the explanations I've been getting online have been incredibly unsatisfying, ranging from "It was an act of mercy for the child to die, he would have had a terrible life!" to "It's OK for God to punish innocents for the sins of the guilty." All of these feel inadequate.

To me, the one thing that sticks out to me is that Nathan says that God "[P]ut away David's sin", which seems to contradict the child's death being a punishment for sin.  Is there an actual satisfying answer to this problem?
The problem here is your perspective. It appears that you don't allow G-d to do as he pleases in that David's punishment was the death of the child. The child isn't punished. G-d does not guarantee anyone any term of life. Life belongs to G-d and he can do with it whatever he chooses. As an innocent, the child is guaranteed eternal life.

So G-d is not unjust because the child wasn't treated unjustly. 

G-d doesn't punish the child for the sin of the parent but there is a principle called collateral damage. If I take LSD and damage my genes, then my child will suffer for my action. In this case David choose evil and David's punishment was the death of the child. This is not unjust on G-d's part.

Secondly forgiveness of sin doesn't alleviate the consequence of sin. If I rob a bank and repent the judge isn't going to commute my sentence.

I hope this helps.