That out of the way, your problem may be due to:
- User installed applications misbehaving
- Malware (though I haven't read of any malware doing this yet)
- OS corruption (of drivers pertaining to charging)
To rule out 1, put your device in safe mode. If the charging behaviour is fine, then you would need to uninstall all installed apps and re-install one by one checking that problem doesn't surface. Painful, yes, to avoid that jump to steps in next para
If the problem persists, you have no other option but to flash stock ROM. Instructions for flashing here. Stock ROM mentioned there is Indian, which should work fine for you or you can download latest stock ROM from sammobile. Make sure you take a backup though- if your device is not rooted Full Backup of non-rooted devices would help else use apps from play store
That should fix your problem, unless it is hardware related (very unlikely)