Even if the math is right on paper, it doesn't always end up so crisp when things come to on-chain execution: high gas fees, bad liquidator work, etc. - can result in the protocol having bad debt and becoming undercollateralized. To prevent it or to retroactively restore capital in such situations, different mechanisms can be put in place. Those include liquidity backstop using governance tokens either by selling them or having LPs do that (like in Aave), having a separate Reserve Fund to pay out liquidity providers (like every CEX has), and so on. Sometimes, these strategies can be combined for extra safety.