Castles have been used throughout history as a form of defensive warfare, especially in Europe. Their strong, armed walls and slit windows allow defenders to hail down arrows at the attackers and still stand a considerably samll risk of getting injured. All in all, these defensive bonuses make the castle the strongest form of European defensive warfare in the MIddle Ages.
The castle was also the dread of criminals as all caught law offenders would be imprisoned in horrible conditions there. This allows it to cut crime in its own city by 50%.