Water Compaction is a Generation 7 ability introduced on Sandygast and Palossand. When the holder is hit by a Water-type move, its Defense rises by two stages. From a neutral stage that is an instant 2x multiplier; the boost stacks to the usual +6 cap for 4x Defense, and any Water hit after that does nothing beyond the damage itself.
The order matters. Damage resolves first, then the ability triggers. If the hit knocks the Pokemon out, there is no boost to use. That is why Water Compaction reads like an immunity but behaves like the opposite: it is at its best on a Pokemon that can survive the Water hit in the first place.
The ability is reactive, not defensive: it fires after the hit resolves, so anything that stops the hit also stops the boost. If a Substitute takes the Water move, the holder was not hit and nothing triggers. Mold Breaker, Teravolt and Turboblaze do not switch it off either — they suppress abilities that weaken or block the incoming attack, while Water Compaction only reacts afterwards.