The problem to this can be lots of things, to figure it out more specifically try to include more details but for now, if your phone keeps restarting it could be a:
# Software Glitch - corrupted files or problematic updates can cause your phone to reboot, try resetting your phone and if the issue stops then some of the apps or files you had before the reset are causing the issue
# Overheating - excessive heat triggers automatic restart, avoid using your phone while charging, close running apps in the background, and check for any physical damage or overheating near the battery
# Virus - malicious software can cause random restarts, try installing an antivirus app or getting rid of any suspicious apps or files
# Storage Overload - Running out of storage can affect the system's performance, try free up space by getting rid of unnecessary files or clearing cached data
etc. There are also a lot more issues it can be, these are the most common problems that you can try, but with more information, we can narrow it down to what the problem is specifically.