Lets collect a bit more diagnostic info here. Install this app [https://www.tunabellysoftware.com/tgpro/|TG Pro] so we can review the systems thermals as I suspect thats the reason your system is shutting down. You'll want the full version here as you want to have it capture the event just at the point of the shutdown. The info is logged and can be reviewed afterwards. You might find some clues before that if the fan is spinning up to a high RPM.
Often times a very dusty system can cause the system to overheat. Also a bad heatsink or failing fan.
What you are running can also effect things as a heavy graphics game or apps can push the systems thermals.