What is an idiom for this whimsical turn of events?

Solution 1:

You got me sweating, exceptional question. I rummaged through some resources and gathered that frustratingly enough there is no to such an extent specific singular word. I've piled some synonyms that can point you to the right direction though:

Nouns: Obviously victim. Sufferer, casualty, fatality. Martyr may be a little inappropriate, due to him/her being uninvolved.

Adjectives: incidental

There is also a phrase I still hold on to: Unwitting victim of circumstance. Circumstance here can be replaced with plight, predicament, ploy, machinations or conspiracy even to convey ill intent.

Hope this helped you at least in the slightest.

Solution 2:

In your scenario, you might say that A took the fall or B, or took the hit for B.

You might even call A the fall guy, except you suggested that B avenges A's death. Usually calling someone like A "the fall guy" suggests that B set A up to take the fall.