When a wash is fermenting, it produces very large amounts of carbon dioxide gas. An airlock, or fermentation lock, allows this gas to escape by bubbling through water. The water allows gas to escape but prevents oxygen from entering the fermenter. This is important because if yeast has access to oxygen, it forgets about fermenting and simply reproduces aerobically.
An airlock also prevents things like contaminants and bugs from getting into the wash.