I'm assuming you already did a simple reboot? If not, follow these steps:
-Press and hold the Sleep/Wake button for a few seconds until the red "slide to power off" slider appears, and then slide the slider.
-Press and hold the Sleep/Wake button until the Apple logo appears.
If that doesn't do anything I'd guess there's a bug somewhere in how your headphones are getting connected/disconnected. Maybe try playing music with headphones, then unplugging the phones and continuing music through the speaker to see if that might "reset" the switch from one to the other.
Still try the reboot first, I'd say!