I had the same problem on my iPhone 4 (iOS 5.0.1)
Specifically:
- No volume control (slider or hard buttons) when playing music, games, video etc
- No sound when playing the above
- Sound and volume control returned when head phones plugged in
- Ringer still worked
I read a thread that fixed it for me.
I noticed it after I plugged the phone into my car stereo (has iPhone docking) and then unplugged it after activating the iPhone and playing a video.
To fix it I plugged it back into the car stereo and activated the iPhone (usually when I plug it in the iPhone screen shuts off and I control the music etc from the car head unit). Sound and volume control returned to the iPhone!!
Crazy but it worked. So I guess some docking stations will do the same thing (not just a car stereos)