There are many scenarios to your problem, but it sounds like a hardware issue.
- Check your processor fan, it maybe faulty so when the processor overheats it shuts down your computer
- Check if the thermal paste on the processor has dried off
- Check your PSU (power supply unit), it could be faulty
- Check if your graphic card is working properly and is it dispensing too much heat or not