A lot of things could be the reason of this.
It could be a malfunctioning stick of RAM or malfunctioning PSU. It also could be heat problems.
I have experienced all the mentioned above. If you got 2 sticks of RAM, then try removing one of them and check if the problem is gone. Monitor your temperatures and check if they are okay, you can use HWmonitor to do this. To check the PSU is tricky, but if you can smell burned electronics while your PC shuts down, then it could be your PSU.
RAM checked OK ay other way to check PSU no burned smell