There are two distinct concepts being talked about in this discussion: felony murder and transferred intent. Felony murder (which I'm using to describe the same provisions that some jurisdictions apply when the victim doesn't die) simply makes a person who commits a criminal act liable for the foreseeable consequences of that act, even when the person does not actually commit the crime charged.
Transferred intent is normally applied where a person intends to kill/injure person A, but instead kills/injures person B. The transferred intent rule simply says that the assailants intent to kill/injure A transfers to B. Since most crimes have a mens rea/intent requirement, without the transferred intent rule, the assailant could not be held liable for injuring or killing B.
Most, if not all, jurisdictions in the US apply the transferred intent doctrine to self-defense/defense of others. If you act in reasonable self-defense and mean strike C, who is assaulting you, and instead hit D, an innocent bystander, your "good intent" will transfer, and, as long as you were justified in the actions you took against C, then you will be justified for striking D. However, there are two major variations on how this is applied. In some jurisdictions, it is an absolute defense. (If you were justified in striking C, then no criminal liability is possible against D.) Other jurisdictions allow criminal charges for striking D where the mens rea element is only criminal recklessness or negligence even when striking C was justified.
This Virginia case has a pretty good discussion of the law of transferred intent applied to self-defense.