If your iPhone keeps restarting even though you are doing nothing that would force it to restart, it could be because of several problems. The first thing to check is the battery because oftentimes if the battery is faulty, it will cause the iphone to keep restarting.
Make sure the battery on your iPhone is completely charged, reset your iPhone and then see if it keeps restarting or not. If it is, then replace the battery and that should make your iPhone stop restarting when you don’t want it to.