Polarity independent flyback diode
Putting a MOSFET inside a bridge rectifier is a good way of ensuring that the MOSFET always receives the correct polarity but there are two issues to consider: -

You'll need to optically interface with the MOSFET to control it because you have &quot;lost&quot; any reference point to actual ground.
There will be losses in that there are two diode drops in the current path.

To protect the MOSFET you can add a zener diode in parallel with it inside the bridge rectifier. It needs to be rated at a voltage greater than the incoming power supply i.e. 24 volts.
Or, get hold of a MOSFET based solid state relay  - these will be optically isolated internally and should do the job for moderate frequencies of PWM (maybe up to 1 kHz): -

Turn on and turn off time are around 1 ms for the device above but there will be quicker devices.
But, you'll still need flyback protection and this can be formed by two series back-to-back zener diodes of the appropriate voltage and current rating.