Generally the battery is the weakest link especially if it has never been replaced before. This is after all about six or seven years old, so a bad battery is very likely. Of course it could be due to some other hardware issue such as the DC-In Board or even the Logic Board (the latter is expensive and not worth repairing especially since the battery likely needs replaced anyway). On older Macs I have seen a bad DC-In Board or a bad Logic Board to cause this problem of a laptop powering off when disconnecting the charger.
If this problem is easily repeatable, then take the laptop and charger to an Apple Store or an Apple Authorized Service Provider to they can provide you with a diagnosis and repair estimate. An AASP may be the better option as an AASP may keep some spare test parts available such as a DC-In Board which can help with the diagnosis by either by quickly confirming that is the bad part, or by narrowing it down to the MLB or Battery. Since Apple decided to glue these batteries into the laptop, there is no easy way of testing another battery to further narrow down the part at fault. Of course more than one part may be needed. The only way to be sure which part or parts is bad is by swapping in known good parts for testing...most users don't have known good test parts handy, but an AASP might, or their Apple service diagnostic may reveal a hardware issue that the consumer level diagnostic does not.
Keep in mind if this is the original battery, then the battery likely needs to be replaced regardless if it is the actual problem here. If a third party battery has been installed, then I would be concerned that it may have failed prematurely or perhaps the laptop was damaged while removing the original battery.
It is also possible there is accidental liquid damage. Probably about half of the repairs I have performed have been due to liquid damage...it only takes one drop of liquid at the right place on a board to cause a failure. A tech really needs to physically examine the laptop for this and to notice any small subtle signs which may provide a clue.
There is usually no good way of testing to confirm which part has failed except with a physical examination and by swapping in known good test parts. A failure like this has three equally good candidates, but being able to physical see the behavior may allow a tech to notice something subtle which could point to the most likely candidate.
You also have to ask yourself how much money you are willing to spend on a laptop which is now considered "Vintage" by Apple where it is no longer able to run the current version of macOS. Some third party apps may no longer be supported on this Mac running Monterey after 2024 when Apple stops supporting Monterey (depends on the third party developers...Microsoft no longer supports Catalina with their latest version of their Office suite although the online browser based subscription option still works).