Randomly or after a set time of use or intense use? Could be processor is overheating past safety thresholds (new thermal paste could fix this IF that’s the issue).
I’d try cleaning vents and fans before changing thermal paste though. Could be they’re clogged and not working right.
Failing that it could be multiple things. But I’d try to address cooling being adequate first. Make sure vents are unobstructed during use. Use it on a flat hard surface, clean the vents with a vacuum and/or canned air duster.