I am also suffering the same issue. Iphone xs getting switch off after connecting the lighting cable. My battery health shows 81% & I have done the factory reset as well but problem still exists.
After removing the lighting cable, apple logo appears and again getting off after screen goes to off.
Note that - apart from playing a song and connecting to the charger, Removing the screen timer do we have anything to recover this issue
Is this happens due to software bug?
Did anyone resolve this issue ?