This diagram shows what happens when a high voltage spike comes through a power line into a switch mode power supply. In this case the sensitive electronics are on the right. The transformer blocks the spike but it can pass via the feedback loop and damage the sensitive electronics. Put an optocoupler on this feedback loop and the voltage spike can’t get past the optocoupler to the output or sensitive circuit.