Greetings!
As others have, I joined the community per this thread. Haha
I also have a Galaxy A51 with this issue (3 days now) and have tried all the above troubleshooting for the issue to remain. Lucky Jstewa22
Although, mine acts differently. I have the persistent notification, but it doesn't show in my bar unless I pull it down. I can charge my phone, but it has to be powered off. Using a backup phone for an alarm in the mornings.
With cleaning (thoroughly) twice; the first cleaning did make charging work a couple of times, but then not. After the second, still nothing while powered on. I often wear carpenter pants with the phone side pocket and my speaker pointed up (as well as my charging port).
I was thinking a deeper clean than I can get would be needed, but that doesn't answer why it charges when its off.
Will definitely keep my eyes out for some other troubleshooting options.
Edit: Two things. One, our persistent notification friend loads up with my UI after reboot. My phone doesn't start loading my background apps till after I enter my password. Two, after playing around to pinpoint which way to go, hardware or software; clicking on the persistent notification and attempting the change from "Connected Device" to "This Device" (which it gives 'Couldn't Switch' before reverting back to "Connected Device") while my phone charger is plugged in instantly made it start charging. But it stops eventually. Will attempt another factory reset tomorrow with very minimal saving of what I have. Too late tonight.
Safe to say this annoying notification is a lead into this horrible error. If you get it, be prepared.