Had the same problem. I read all the suggestions and this is how I fixed my Samsung s5. I dipped a toothpick in WD-40 and used it to clean all the connections in the phone's charge port. I rolled the toothpick around inside the port and I could see the dirt on the tip of the toothpick. I used 2 toothpicks and used both ends of each one to collect all the dirt in the port (my charge port cover fell off months ago so it was dirty).
This problem was also causing the phone to turn back on after I turned it off - so I fixed 2 problems with this fix.