Hi, thank you for contacting JustAnswer.com. My name is Russell. I will do my best to provide the right answer to your question.
Your phone might perhaps have a problem with overheating, or it might be getting flakey and erratic as an early sign of future failure.
Have you downloaded and installed many apps onto it?
As for shutting down or restarting... that might be a sign that the battery that powers it is getting unreliable... or more likely, that the battery has gotten loose in its compartment. Or, the battery's terminals may need a trifle of cleaning:
Try cleaning the terminals in the battery compartment, after removing the batteries, first by rubbing off with a fresh pencil eraser, then by wiping the terminals off with cotton swabs moistened in rubbing alcohol, then letting them dry off for 5+ minutes with the battery compartment door open, then try turning the phone On again.
Let me know how that goes, after you have tried that.