MOSFET broke after attaching capacitor bank
Your gate drive voltage is too low. That MOSFET  needs 10V to turn on completely. 5V just  barely clears the 4V threshold when the MOSFET just barely starts to conduct. DO NOT use the Vgsth if you intend to use your MOSFET at a switch. That is the voltage it just barely starts to conduct at. Use a Vgs at least as high as the one used to obtain the given RDson. The Vgsth is for using the MOSFET as an linear/analog device.

According to Figure 1 in the datasheet, with 5V across the gate-source and 27V across the drain-source (I'm ignoring the solenoid resistance since it drops relatively little voltage), the MOSFET saturates at 10A. That's 270W being dissipated in your MOSFET.

And Figure 1 is at 25C. Your MOSFET is heating up while it does all this which makes it operate more like in Figure 2 where even more current being conducted. In this case it is saturating at 30A with a 27V drop which is ~800W of heat being dissipated.

With a listed junction-to-ambient thermal resistance of 62 C/W, that's a temperature rise of 17,000 and 50,000 Celcius, respectively.

Also, look up gate drivers and consider whether you need one or not for your MOSFET or if directly driving the gate capacitance from a piddly low-current I/O pin is sufficient for your application.