Simplest first. Inspect the port and make sure their is no debris in there.
iOS compatible headsets can bork the disconnect recognition in Windows Phone. It's the way the contacts are wired on the male plug.
Solution is a Soft Reset (without headset plugged in, of course).
Hold the Volume Down + Power buttons until the phone vibrates and reboots (about 10 seconds). If this solves it, use a different headset in future and avoid "iOS Compaible" units.
If Soft Rest does not resolve your issue, then you need a Hard Reset.
Power off the phone > hold Volume Down > press Power > keep holding Volume Down until you see the exclamation (!) screen, then immediately release the Volume Down
Now tap Volume Up / Volume Down / Power / Volume Down
You should see the spinning gears and your phone will reflash the last OS version held in recovery. You do loose data, but get your phone back. Sign into your Microsoft Account and restore your backup during the set up.
These will eliminate 99% that it is software. Seek repair if this does not fix your issue.
If you need additional help or have more questions or details to share, please join the site so you can reply in this thread... Please see
this link for instructions on how to join Windows Central.