I'm with Alvin. How can you tell it gets too hot? Are you running a CPU temperature reading on it? If so, what's the temperature you're getting?
Also, we need to know your specs to help. That means the CPU, the motherboard, RAM, PSU, HSF, and so on. Include the model numbers whenever you can.
Assuming you've accurately picked out the problem, it's caused by the CPU getting too hot. In order to prevent it from bursting into flames, the computer shuts down.
This problem is most often caused by improper cooling. This is caused by several things, including the case fans not running (or not working period), airflow being blocked inside or outside the case, not properly installing the heatsink, not appling the thermal compound correctly or in enough quantities, the heatsink's fan not being plugged into the motherboard (which should cause it to not boot), and many other factors. To narrow this down at all, we need a lot more information.