Not sure about that one, you could try making two triggers something like this:
Event
A unit dies
Condition
[Triggering unit] equal to (Hero)
Action
Change ownership of [Triggering unit] to (Player B)
Event
A unit is revived
Conidition
[Triggering unit] equal to (Hero)
Action
Change ownership of (Hero) to (Player A)
My only concern is that you may not be able to change the ownership of a dead unit or hero, also, is the idea that Player A loses a pre-placed hero, or trains/gets one and later loses that?
If it's that latter some alterations will be required, also the idea is that Player B has a unit or building that has the ability to revive heroes, right?