My headphone jack on my Nexus 7 2012 works only half the time
I think this is just general phone wear and tear. The headphone jack could be partially damaged due to water over time. You could get the headphone jack replaced and see how that goes for you but if the phone is 5 years old then this might be a good time for an update.