Sounds like something was installed or downloaded that is messing with the phone. Try putting it in "Safe Mode" (instructions below) and see if WiFi turns off while in there. Granted you can't use most apps in that mode, but you are using it just to test he WiFi. If it stays on, then the problem is something on the device. Bad app, malware, virus, spyware, etc. Which will then have to be found and removed to fix the problem.
You may also want to check the modem/router that it is connecting to and make sure that it isn't having any issues or that the ISP isn't causing the service to go out off and on. It happens a lot and some devices are way more sensitive to this than others are. If that is the case, try resetting (turning off and...