This looks to be a 2009 small desktop so over that time has the usual cleaning been done?
(Google "How to clean my desktop computer?")
Also at 7 years the heatsink compound may have dried and cracked which means we replace that (figure 20 bucks cost in parts.)
You ask for the exact problem, but not the solution so the exact problem is in your top post. I know that such an old machine may need cleaning and heatsink compound replacement but I would never tell anyone that's it. The age means it could have a failing part or one that has become heat sensitive.
I have hp compaq dc5850 small form factor and the problem which I have been facing for about a week now is that my CPU keep on working properly but suddenly LCD display goes off and keyboard and mouse stops working. What i found that it happens because of heat-up but still I will prefer the advice of profrssionals. So firstly tell me either its a problem or not and if it is please tell what exact problem could it be ? And advice me a reasonable solution.