In reading all the replies I am convinced that this is a software problem. I was getting the same message on iPhone 15 Pro when charging. I admit that I use a third-party cable and brick, but I don't think that matters. If Apple wants to blame it on the cable, I consider that a cop-out.
The phone still charges, but you can't charge it on your nite stand. It will keep you awake. I did a few things to try to fix it as follows:
Updated phone to ios 17.1.1
Turned off low power mode
Turned off StandBy
Turned off Clean Energy Charging
Apparently, I changed its behavior. I now no longer get the accessory power message. Instead, I'm getting the bell sound during charging each time the battery reaches the next percentage of charge. Another annoyance.
So, you see. It is a software problem that Apple needs to fix.
It is really a nice phone, I will not return it. I am patient and will wait.