This issue can be caused by a few different things, but the easiest solution is to turn your phone off and on. However, if this doesn’t work, then you may need to perform a factory reset on your phone. Make sure to back up your data before performing a factory reset.
Press the power button to turn the phone off and then turn it back on. Make sure you have power, try plugging it in and charging it for a while. If that doesn’t work, try to reset your phone by pressing both the power button and the volume down button at the same time for 7-10 seconds.
If your phone thinks it's connected to headphones, it's usually because your phone is connected to your computer. This can happen if you plug your phone into your computer with a USB cord that has a built-in microphone. Just unplug the cord from the computer and plug it into your phone again.
You can try to restart your phone, but if it doesn't work then you need to do a factory data reset. Go to settings > security > reset > factory reset. If it doesn't work, you may have a hardware issue and you should take it to Apple to get it fixed.
Fixing this issue is pretty easy. All you need to do is go to settings > Bluetooth and turn off Bluetooth on your phone. I also found that by simply turning off Bluetooth on my phone, it began to recognize my headphones.