When you connect the charger and do not try to start the laptop does the laptop indicate that the battery is charging?
If so try gently moving the charger's plug in the laptop’s charge port from side to side and up and down to see if the charging light turns on and off and if you can detect any movement in the port at all.
If so I’m wondering if it is a loose or faulty DC-In jack on the motherboard. If so this may be why the problem is happening. The battery perhaps cannot handle the load any more (possibly due to not being correctly charged over a period of time because of the jack problem) and when the charger is plugged in, if the jack moves for whatever reason, power would also be lost to the motherboard and it would shutdown.
This is only conjecture on my part. You would need to open the laptop and inspect the DC-In jack to see what its’ connection is like and maybe even have to prove electrical continuity through the jack with an Ohmmeter etc