Random restarts are often hardware, not software.
Common hardware causes:
1. Worn battery that can't supply peak power, especially when opening the camera.
2. Stuck power button, sometimes pressed by a tight case.
3. Overheating.
4. Loose battery connector after a drop.
5. Corrosion after water.
6. Failing storage chip.
Try first: remove the case, update the phone, check battery health and safe mode. If it still restarts, have the battery and buttons checked.