It must be one of the three things. Try these solutions in the order which I have posted them in.
# Software problem; try a hard reset of your phone using [https://www.wikihow.tech/Do-a-Hard-Reset-on-an-Android|this guide] (you will lose all of your phone data doing this, so back up your data accordingly)
# Battery problem; replace the battery
# Charge port problem; motherboard replacement is required due to the charge port being soldered to the mobo.