In a case here, someone broke the keyboard key to powering on/off a laptop putting perfume around the room which finished falling a bit the keyboard.
Then, to power the computer on you had to press the button behind it at the same time in a repetitive way but once you stopped the power button powered off the computer.
Cleaning the keyboard insides didn't solve the situation and given we had no way to get a replacement, the laptop finished being sold by parts to recover some money.
In other case, was just the battery pins not being well attached and if you moved the laptop in a specific way, the battery disconnected and the computer was powered off.
A case with the heatsink is a situation that happened to me in a computer tower because Intel heatsinks have a weird way to get attached, so the processor arised its temperature a lot when was being used and suddenly powered itself off. I had to unmount it, mount it again and ensure, by physically trying to pull it out and with a light to see each corner, that was well attached.