the importance of castles in medieval times