Castles served a primarily military purpose -- they housed armies and acted as garrisons that controlled a particular territory. Many castles were part of fortified towns and sheltered the surrounding villagers in times of war and siege. As time went on, castles also became residences for lords and kings.