Mirror Damage is a monster-only spell which causes any damage inflicted on the caster to also be inflicted on the attacker, similar to Yredelemnul's Pain Mirror ability. This damage is not affected by any resistances you have: whatever damage the caster takes, you take too (although deep dwarf damage shaving still works). The caster's glyph will change colors while this is in effect, and it lasts for roughly 20 turns.
The following enemies cast Mirror Damage:
Any time you see either of these casters coming at you, pay close attention for them to begin use of this spell. Any time you see the message, "X kneels in prayer and is bathed in unholy energy," that means it has activated Mirror Damage. Try to snipe these casters when their shields are down, and focus your fire elsewhere in the meantime. Alternatively, summoned allies can fight them for you, but this will chew through your army quickly.
Be aware that Mirror Damage can affect you even if the caster is out of your line of sight. Be extremely cautious using high-level spells while fighting enemies with Mirror Damage. You might strike them off-screen, particularly in the case of spells like Fire Storm and Ice Storm. Even if you hit them while their shields are down, they could raise them at any point during your spell's duration.