Fortifications were not unknown in Roman Antiquity (the word "castle" in English and "chateau" in French both derive from the Latin castum, "military camp", "fortification") and were prominent elements of warfare, to the point of often being the basis for the layout of newly founded cities and towns which would evolve from the military encampment of the fighting men, often in recently annexed or pacified areas.
However, fortifications were rarely seen outside of cities in Classical times: something which becomes its polar opposite during the Middle Ages, after a swath of political, social and economic changes. The biggest portion of these changes is credited to be the fragmentation of political power occurred after the destabilization of the Western Roman Empire and the structuring of the post-Roman or Romano-barbarian kingdoms of the VI-VIII centuries. Such fragmentation, has been debated, had two potentially major factors: the erosion of state influence and the Germanic customs and laws "grafted" onto the Roman ones during the Migration Period.
Taking Italy as an example, the Langobards from 568 to 774 were a people which in some ways contemplated the customs codified in the Salic Law of 507-511, such as male-only inheritance, but also conceiving royal status and realm as private possessions of the family bearing them, resulting in their division upon a ruler's death. Most famously, Pepin the Short, the Frankish king of France in the first half of the VIII century, split his kingdom in two since he had two eligible male sons - Karl and Karloman, effectively creating two more realms.
Such occurrences happened on a micro level as well, especially when taking into consideration the creation of clientele and personal bonds between individuals of differing status and the usage of these fealty structures in an administrative fashion both by the king and other ruling individuals (dukes, counts and so on, creating the premises of what has been called "vassalage") emphasized a power projection model which was based outside of cities (which, especially in Italy, were usually organized by the power of bishops and archibishops) and in the rural areas (where most of the wealth of the land-owning elite was concentrated, both in the way of monastic possessions and private estates, often linked to previously expropriated holdings).
Thus, subjugating the centres of power meant taking the fortified homes of individuals holding either unlawful authority over a territory in a de facto way (what has been called "bannal lordship"), or public offices assigned by a ruler which were to be performed through the resources provided by the area a loyal man was commandered to oversee (counts in the early Carolingian empire were, in fact, public officials drawn by loyal families of landed aristocrats whose title was not, in the beginning, hereditary).
This is a broad overview of the transition between the Late Antiquity and Early Middle Ages, where the decay of the city as a symbol and tool of power tightly connected with state authority and the rise of the rural fortified spaces of private influence was a major factor.
I hope it answers your inquiry.