Take the blower housing off and clean out all of the cooling fins, remove any debris in there.
While you are there, set the valve lash 0.004" both sides.
When running check the voltage at the battery is if is less than 13 V you have a charging problem.
The thing under the carb is a shut down solenoid that closes the fuel supply to the engine .
Some of them are sensitive to voltage so will shut down when volts drop below 10V.
A duff battery & alternator will run down very slowly while you are mowing .
When the mower sits for a long time, the battery equalizes and the voltage rises slightly, just enough to open the solenoid when you turn the key.