It could be a number of things from software to hardware.
Try turning off data when you turn on the WiFi and see if that resolves it. Some devices do not like running both at the same time.
Additionally, you may want to see if it is actually caused by something on the phone. Bad app, virus, malware, etc. Try turning off the phone and then start it up in "Safe Mode" and see if it will allow you to turn in the WiFi while in there. If it does, and the phone stays on, then you have something on the phone you need to remove.
To get into "Safe Mode" please do the following.
1. First turn off the phone.
2. Next press and hold "Power" until you see the manufacturers logo on the screen, then release the power button.
3. "Quickly" press "Volume Down" and hold it for few seconds until you see the message "Safe mode: ON" or something similar.
4. If you wanted disable it, simply repeat the steps above, and you should see "Safe Mode: OFF" rather than on.