Good advice overall from the folks here.
And like Ben said you ought to try a new charging port to rule it out if this issue arises again. Just don't use a cheap part as the lightning/charging port has many functions: charging, mic, antenna, headphones jack. If you purchase a cheap part, any or all of those functions can be bad.
To do this: power off phone; unplug battery; unplug charging dock; overlay new one and plug it instead; plug battery back; start phone and test. If your issue is solved, repeat above steps but this time replace charging dock.
Here's the replacement guide for the charging port. It also has links to the needed tools and parts.
Next would be to have it examined by a repair tech that can perform micro soldering.
There's a link on my profile with a number of them that can do this repair (mail-in or walk-in).
However, if your phone is still under warranty you can have it checked at an Apple Store. They might replace it for free if there is no evidence of physical damage nor tampering.