This issue can be software or hardware related.
When it’s a software issue, some program or windows is crashing. Some systems will just reboot, some will pause on the error screen.
When it’s a hardware issue, either there is a bad, part, or something isn’t set right with the timings, or just an incomparability with a component.
Restarts are a pain unless it happens often. The occasional restart can be one the most difficult to track down, because you have to “wait” for it to happen.