I have an iphone6s+ which i had for 4 years and it won't charge unless the iphone is turned off and has a low battery?

The cable isn't the problem and the charging port is completely clean from any debris or corrosion.
what do i do?
(it has the latest ios system on it too)

Try doing a hard reset, alot of time if the phone has any software issues it can be fixed by doin this---Press and hold the Home button and Sleep button together for about 15 seconds till you see the Apple Logo appear then release buttons. The phone will turn off and restart and after it does your phone should charge normally

Have the battery replaced.

After 4 years, it's typically time to replace the internal batey. You can take it to an Apple store and they will send it out for replacement.

Take it to an Apple Store to be seen about.

May also want to look into replacing as well

I replaced the battery at a cell phone repair store for $50 and my iPhone 6 still works great afterwords. Phone batteries only have a set amount of charge cycles, after that the battery starts to fail.