Fermentation is Sugar (malt, fructose, or sucrose) being converted to CO2 and ethanol alcohol. Firstly if this CO2 is not vented out, it will build up pressure and will cause the home brew fermenter to explode. The primary job of an airlock is to allow this CO2 to be safely vented out.
Second problem is that if oxygen or outside air is allowed in, this will react with alcohol and convert it to vinegar (acetic acid). The reason airlock is named as an lock because it should lock the outside air out.
Arishtam keeps two varieties of airlock. The traditional S Type and the modern 3 piece airlock.