When the Reconquista advanced, those border castles lost their initial purpose, and, as in the rest of medieval Europe, they were used as noble residences and fief-keeps.
In some locations, such as the Basque country, fiefdoms did not exist as such, and noble families could not afford nor did they need huge fortresses, giving rise to many tower houses.
In Muslim Spain many castle-palaces were built: the petty taifa kingdoms that arose after the fall of the Caliphate of Córdoba were militarily weak thus castles began taking on a more aesthetic purpose.
Although the order was not completely carried out, the War of the Germanias, a rebellion against king Charles V in the early 16th century, forced the new Spanish Habsburg dynasty to continue the process, and many castles were demolished as well.
Most of the castles in Spain were successively abandoned and dismantled, Spanish kings fearing noble and peasant revolts, especially in the newly conquered lands.