I have been through this on my iPhone6 and tried all the options, and I think I found the one that works plus some other temp fixes. And it's clearly my phone, not chargers, because the same chargers work just great on my iPad.
Fail-safe option:
-- plug in charger, "accessory not supported" will pop up, turn off phone. Wait a normal charging time. Turn on phone. Phone will be charged. It sounds like from others, this option will work every time, and for 4+ months it has for me! The downside: no phone backups. But hey, it's better than forking over $ for a new phone when you're still paying off your current one. Also, don't turn off phone and then plug in, because it will just turn on and not recognize the charger.
Other options that may work, temporarily, and will allow you to back up your phone when it is working:
-- early on in the problem, turning my phone off and on worked. But that stopped.
-- "resting" my phone worked for a while, but that also stopped. Meaning if I tried to charge it when I went to bed it would give the "not supported" message, but if I plugged it in first thing in the morning before I used it at all, it would charge. Sometimes I'd have to rest it for an overnight, sometimes just an hour or even half an hour.
-- I got a non-Apple approved charger (gasp!), but hear me out. It's one of those magnetic chargers. So you keep a piece in the charging port in the iPhone at all times, rather than repeatedly adding and removing the charger. In theory it will result in less damage to the port. And I didn't get this charger until after my phone stopped charging while on all the time. But here's the odd thing: after switching chargers, sometimes my phone charges while on now! Not all the time, it goes in and out, weeks where it will charge when on and then weeks when I can only charge it by turning it off while plugged in. But when it's working correctly with the mag charger, every time I've tried switching to the Apple-approved charger, it stops working. So now I exclusively use the mag charger.
Most importantly, if your phone is less than a year old, take it in to get it fixed/replaced for free! Mine started doing this after 9 months, but it eventually charged when still on, so I didn't bother taking it in. It took until 16 months to stop charging when on reliably, and by that point Apple laughed at me when I said it was an issue before the one year was up and it's my fault for not taking it in (I mean, it is, but they were still pretty condescending about an issue with their product)