It sounds like it's triggering the headphone jack sense feature of the sound card, but not recognizing when the headphones are being disconnected. If that's correct, it should be a control that you can see with the amixer command (something like "amixer -c 0 sget 'Headphone Jack Sense'").
This is a little old, but maybe it's more helpful:
http://www.ces.clemson.edu/linux/alsa.shtml