both software and hardware errors may lead to this case.
firstly, you may take out the removable battery and plug it with outlet. If it doesn’t help, it means it’s not battery problem.
Then, try resetting SMC:
Make sure the Mac is shut down.
Plug the USB cable to the Mac and power source.
Press ''''''Shift + Control + Option + Power keys together for 10 seconds.
Then, press Power to turn on the Mac.
Check more [link|https://www.minitool.com/news/mac-keeps-shutting-down-randomly-fix.html|details].