I have a Samsung Galaxy Ace 3 that turns off when it sleeps or locks, but that only happens when it has internet access, not necessarily with WiFi on. So if I want to use the phone I have to disable the WiFi so that I can lock it, and if I want to use the internet I have to make sure it doesn't sleep, by touching the screen and stuff.
It does not turns off at random, only when WiFi is on and it sleeps. Sometimes it takes a bit of time for it to turn off even when the screen blacks out, and sometimes it instantly turns off when the screen goes black. Also, if I set WiFi to be disabled during sleep I can't receive email and stuff when the phone is locked, but it does not turn off.
So I prefer if there was another fix, I can't seem to find any problems as the phone worked fine before. I have not installed anything and I even did a factory reset from the backup menu in Settings.