Chosen Solution
How do I prevent my phone from doing this?
It might be a worn out battery issue, a hardware issue at component level or else. You may try restoring your phone but if you have a hardware fault you run the risk you won’t manage to activate the phone anymore. If the battery wasn’t in good shape before the reboots a battery replacement would be the first step to take. Hard to give any further advice without some basic info on the iPhone history.