If it is a 15-inch model, it is likely caused by graphic components fault, whenever the Mac switch over the discrete graphic chip the Mac will reboot or shutoff. You can google online, there are no permanent fix for this issue. Apple had officially recall this problem in the past but long expired now.
If it is 13-inch you might want to check the hard drive cable.
MacOS X Macbook Pro issues, Random restart
May 8 2019, 10:14 AM
Quote
0.0160sec
0.91
7 queries
GZIP Disabled