Music starts automatically when headphones are plugged into the iPhone
Most normal headphones don't do this but some might or might not start playing. Try pausing your music before you unplug. That should work as a temporary fix.