I solved the issue by uninstalling one by one all the apps I installed just before the problem started. And it seems that WSM tools was the problem, maybe I installed it in the wrong way, but after I deleted it the phone stopped from shutting down by itself.