The first and most obvious purpose is to protect your birds from predators. Some of the more common predators around here are: stray dogs, coyotes, raccoons, possums, skunks, owls, hawks, bobcats and foxes. Chickens are particularly vulnerable to predators at night due to their poor night vision, so even if they are free-ranged during the day, they will need a safe place to stay at night.
Second, housing — much like it does for humans — helps moderate the climate or weather conditions inside. Shelter against rain protects (for both the birds and their food supply), a windbreak during cold, windy weather and shade from the summer sun. By moderating the weather conditions inside the coop, we provide an environment in which the chickens can thrive.
Third, housing “contains” the poultry. It keeps them contained and out of your garden, off your porch, out of your wife’s potted plants and out of your neighbor’s yard — basically, it keeps them out of trouble. But also, it keeps them where you want them. This opens up opportunities for your chickens to have a more symbiotic or synergistic relationship with the rest of your homestead or small farm.