Although this is rare, rust and corrosion in the plug or connector, can be the cause of the problem. Unfortunately, if you find yourself in a situation where the jack is rusty or badly damaged, look for a new headset instead. Ask a technician to replace the jack if it is rusty; you’ll know it if you see some rust sticking to the plug.
I hope you managed to use the solutions and information in this article “how to fix a loose headphone jack”. Remember that your phone is under warranty, so if the solutions feel too intrusive or complicated, go to your device brand’s nearest service center and secure the jack.