The first automatic ability of this card checks the cost of the targeted resonator, as well as the number of Four Sacred Beasts you control, upon resolution of the ability. Any targetable resonator is a legal target, but the targeted resonator will not be returned to hand unless its cost is less than or equal to the number of Four Sacred Beasts you control.
The second automatic ability creates a trigger that can be responded to. Once the trigger resolves, the next source of damage to Xuan Wu is prevented, no matter the source. For example, casting Thunder on Xuan Wu after its ability resolves will "waste" the prevention effect and the attacker will be able to deal damage to Xuan Wu.