I use a Windows laptop that sometimes switches itself off spontaneously. It then shows a blue screen for a second, where it says "lock…" and then it behaves like in energy-saving mode (screen switches off, but background processes continue to run and after about 30 seconds you can switch it on again at the push of a button). This mainly happens when it is not connected to the charging cable, but the laptop is then usually between 70 and 80%. Sometimes the computer shows similar problems and then it has less than 15% for a second and then normal again.
Would it make sense to get a new battery or could it be something else?
Sounds like a battery. Take it out and clean the contacts!