Well... let me think.
If the buildings are owned by a single player (Player 12, say) and Player 12 will never have any other units, then;
EVENTS
A unit owned by Player 12 is attacked
CONDITIONS
Life of attacked unit is less than 1000
ACTIONS
Set life of attacked unit to max health of attacked unit
Set ownership of attacked unit to owner of attacking unit
If you want players to be able to capture other player's buildings, then;
EVENTS
A unit is attacked
CONDITIONS
Life of attacked unit is less than 1000
Any of the following conditions are true:
Type of attacked unit equal to BuildingA
Type of attacked unit equal to BuildingB
etc.
ACTIONS
Set life of attacked unit to max life of attacked unit
Set ownership of attacked unit to owner of attacking unit
I'm pretty sure that will work. I don't have World Editor available right now, so I don't know if those are the exact Events/Conditions/Actions. But anyway, good luck.