ESP32 is stopping working
If I were you I would check those things below: 

1) I would provide +3.3V 0.8A power supply for the ESP's Vcc
2) I would add 10uF in parallel with 100nF capacitors near Vcc pins of ESP
3) I would put a flyback diode like in the schematic below in order to protect the transistor from reverse current due to coil inductance.







simulate this circuit &ndash; Schematic created using CircuitLab

4) I would also put a pull-up resistor at enable signal of ESP32 in order to prevent restarts that are caused from noise. 
5) And finally I would check what current my power supply can provide and how much current my whole system needs in order to operate. (Solenoid valves draw very much current at the beggining (5-7 times bigger than their nominal current) and they cause big voltage drops)