>>556957does it work without battery when you plug it into the wall?
if yes, then buy a new battery. current one's probably dead.
if not, then you need to investigate cause of shutdown. a lot of the time it's overheating and the system shuts down to protect itself from damage. clean up the fins with compressed air. if the fan isn't spinning because it's stuck by dirt, you'll need to clean it up too.
https://www.techadvisor.co.uk/how-to/laptop/how-clean-laptop-fan-3417484/https://support.hp.com/us-en/document/c01657439dust will block heat from flowing out. and non-spinning fan can't evacuate heat.