There Can be many reasons for this problem you faced..
Are you getting any error message before computer shutdown????
This issue might be to corrupted power settings.
To diagnose and fix this issue, try the following methods.
Method 1: Power troubleshooter.
I would suggest you to run the Power troubleshooter and check if it helps.
Press the ‘Windows + X’ key on the keyboard.
Type troubleshooter in the search box and then press Enter.
Select Troubleshooting. Click on view all and select Power.
Click next and follow the on-screen instructions.
If the issue still persist follow the below method.
Method 2: Restore Power Option Settings.
I would suggest you to restore default settings of power plan and check if it helps.
Press Windows + X, and select the option Control Panel.
Click on the Power Options icon.
Click on Change advanced power settings.
Select the option “Restore default settings for this plan”.