Restart your phone
As with most technology, a restart of your iPhone can help fix many issues your device might have. It's always worth taking a few moments to restart your iPhone by powering it off and then on again to see if that happens to fix the issue.
Read more: How to restart and force-restart any iPhone model
Clean your headphone jack
One of the reasons your phone might get stuck in headphone mode is that there's debris of some kind in the headphone jack. Even a small amount of dust can cause an issue, so it's worth cleaning with compressed air even if you can't physically see anything in there.
Turn off Bluetooth
If you've been listening with Bluetooth headphones, your iPhone may believe that it's still connected to the headphones even after they turn off. Try turning off Bluetooth on your iPhone through the Control Panel or Settings app.
Check for water damage
You may think that since you haven't dropped your iPhone in the toilet or sink, you couldn't possibly have water damage, but that may not be the case. To check if moisture is the issue, look for your iPhone's LCI (liquid contact indicator), which will turn red when it has come in contact with water. To find out where this indicator is on your iPhone model, click here.
Contact Apple for further support
If you've tried seemingly every possible fix to get your iPhone out of headphone mode but are having no luck, it may be time to reach out to Apple for further investigation. They'll be able to tell if you're having a hardware issue, and fix or replace any relevant parts that are broken or malfunctioning. You can contact Apple by phone, online, or — better yet if you're looking for a quick diagnosis — go to an Apple Store.
Related coverage from How To Do Everything: Tech: