They retreated underground during times of invasion. At least some of these underground cities were not discernible from the surface. Entrances were hidden. Sometimes people just preferred it down there; the weather is better.
Constructing these complex dwellings must have taken a considerable amount of time to plan and build. Fear of invasion could not have been the primary motivation - unless they had several years’ notice.
I think your comment “the weather was better” is the most likely reason for their construction. Good shelter from severe weather and later from invaders.