When you connect a HDMI cable to the Raspberry Pi, it assumes that you are connecting it to a television, so the sound is also switched over to the TV.
This may not be what you are wanting. If you want the sound to use the 3.5mm socket, enter the following:
sudo amixer cset numid=3 2
Raspberry Pi is a trademark of the Raspberry Pi Foundation