There are many approaches to enclosing speakers, some are sealed enclosures, some are ported, and some are just plain open - backed. the reason for this is simple: they make it much easier to set up the speakers. Everything's in one unit and the drivers are kept in the right position, so they work together to produce the best sound. Enclosures are usually built with heavy wood or another solid material that will effectively absorb the driver's vibration. If you simply placed a driver on a table, the table would vibrate so much it would drown out a lot of the speaker's sound.
since the diaphragm is moving back and forth, it's actually producing sound waves behind the cone as well. Different enclosure types have different ways of handling these "backward" waves.
The most common type of enclosure is the sealed enclosure, also called acoustic suspension enclosure. These enclosures are completely sealed, so no air can escape. This means the forward wave travels outward into the room, while the backward wave travels only into the box. Of course, since no air can escape, the internal air pressure is constantly changing -- when the driver moves in, the pressure is increased and when the driver moves out, it is decreased. Both movements create pressure differences between the air inside the box and the air outside the box. The air will always move to equalize pressure levels, so the driver is constantly being pushed toward its "resting" state -- the position at which internal and external air pressure are the same.
Other enclosure designs redirect the inward pressure outward, using it to supplement the forward sound wave. The most common way to do this is to build a small port into the speaker. In these bass reflex speakers, the backward motion of the diaphragm pushes sound waves out of the port, boosting the overall sound level. The main advantage of bass reflex enclosures is efficiency. The power moving the driver is used to emit two sound waves rather than one. The disadvantage is that there is no air pressure difference to spring the driver back into place, so the sound production is not as precise.