Hello!
Have you checked if there's an option on your phone such as RESUME ON WIRED HEADSET? You can uncheck that and there's another one PAUSE ON HEADSET DISCONNECT, you can check that option so whenever you unplugged the headset, the music will pause.
Let me know if that helps.