The hollower and heavier the wave, the more water that is crashing down. (If its not hollow, there's no barrel, or the water just kinda mushing into a barrel.) As the wave breaks, there is a pocket of air that gets trapped in the barrel. Waves break in line, so one side has already been cut off, and the other is having air being trapped as it continues to break. When the wave finally slows down near, the air has a chance to escape, and gets spit out with water. My take on it. I'm no scientist.
tbing is more pretty much right. It has to do with the pressure differences. Just like high and low pressure in the atmosphere create wind. As the lip crashes down it puts force inside the barrel and creates high pressure. The air is pushed outside the barrel towards the lower pressure. Have you ever felt the reverse spit, where the spit comes toward your face? Sometimes, it can be painful if you get the spit stinging you in the face.