My Lumia 535 automatically off n restart even while I am calling, gaming etc. Also restart when phone not in use.
Check the battery on the back, make sure it fits properly.
If it is and restart persist, I suggest that you install Microsoft's Stop Restart App (link)