Often this type of behaviour can result from CPU overheat problems. The cause of the overheat may be poor airflow as a result of dirt/dust, a failing fan or a bad thermal connection between the heatsink and CPU. The CPU shuts down if beyond its normal max temp to prevent damage.
Probably the first place to start is to have a look at temperatures & fan speeds using something like Everest Home (its free) click here.
You could also have a look around inside to see if everything is clean. Make certain you turn off and disconnect first.