Symptoms and background:
On my iPhone 5 (running iOS 6, and then 6.0.1), when using the iPhone speakers it would not play music, system sounds like the preloaded text tones, keyboard sounds, and similar. The speakers would play my custom ringtones, calls on speakerphone worked, and regular ringtones worked. When I looked at the Airplay menu, the option for iPhone was never there. However, the option for headphones was, even though nothing was plugged into the headphones jack.
Solution for me:
The fix that worked for me was the following:
I went into Settings>Sounds and then under Ringer and Alerts, I turned off the Change With Buttons setting. I also turned the Ringer and Alert volume slider all the way down and then back up again. Then, the things that hadn't been working through the speakers began working. Next, I went back into the settings and turned the Change with Buttons setting back on and everything continued to work.
I'm not sure if I needed to do both things to make this work. My guess is that turning the Ringer and Alerts volume slider down and up in the Sounds pane was probably unnecessary, but in case it was needed I included it in this post.
Hope this helps someone.