If you put the phone in safe mode, are you still experiencing this issue? This will help determine, if it is a software problem or a hardware problem. To put the phone in safe mode:
Turn the Galaxy S21 off
Wait 5-10 seconds after the display turns off
Then press the Power button for a few seconds
Let go of the Power button when you see the boot logo appear
Then immediately begin pressing (and holding) the Volume Down button
Continue holding down the Volume Down button until you boot into Android
As soon as you boot into the Android OS (after following the tutorial above), you will notice there is a watermark in the bottom left corner of the screen. If you do not see the watermark that reads “Safe mode” then your Galaxy S21 is not in Safe Mode
You may also notice a persistent notification telling you that you’re in this Galaxy S21 Safe Mode as well.
When in safe mode, if you are still experiencing the phone powering off while the device is on + charging, then you know it is a hardware issue and not a third-party app causing the problem.
To boot out of safe mode, just restart the phone 😁. Hope this helps! 😉