They usually did. Until the late middle ages, castles were very difficult to sack, and were often avoided if possible. The sieges you see in movies (like Helms Deep) were quite rare. read more
Often times attacking armies would wait outside and try to starve out the castle dwellers rather than attack them. This is called a siege. Many castles were built on a spring so they would have water during a siege. read more