How to diagnose powering damages and protect again surges?
Put a diode in series with the 24 volt feed to the sonoff module so, should the motor decide to draw excessive currents, it doesn't try and extract that current from C23. That could be one reason.

The other candidate is that you allowed the motor to put braking energy onto the 24 volt line and destroyed the capacitor due to over-voltage. This would require a fix that uses a bulk electrolytic capacitor in parallel with the 24 v DC motor terminals so that it (the added capacitor) took the brunt of the energy during braking.

However, if you don't dissipate that energy the voltage could creep up so I would be considering adding a voltage regulator to feed the sonoff module.

Of course, you may just have been unlucky and C23 was going to fail anyway.