Please do try these troubleshooting steps that may help.
- First is to do a hard reboot, remove the battery and unplug the AC adapter then press and hold the power button for 20 seconds then try booting it up again.
- If the same problem will persist do remove the battery again then power it with just the AC adapter connected and see if it will boot up and stay on with just the charger connected.
- But if it will stay on that could only mean that the battery is faulty.
- Next troubleshooting if the laptop will still shutdown with just the AC adapter connected is to clean the inside of your laptop since overheating can be an issue.
- Open the laptop and remove the dust off the fans and apply new thermal paste of the CPU and GPU.
- Do also test the laptop in BIOS and observe if it will still shutdown by itself because if it will that means it's a hardware problem.
- If all these will not work that could also mean it's a motherboard problem.