Developing high-performance aerogels has long been a hot topic in the fields of insulation and thermal protection. Nanofiber aerogels with ultralight weight and high porosity have recently emerged as promising candidates. However, the weak inter-fiber interaction hampers the robustness of the three-dimensional network, resulting in poor overall mechanical properties that hinder their wide adoption. Herein, we propose a novel template-anchored strategy for constructing polyimide hybrid nanofiber aerogels. By utilizing self-supporting chitosan as a sacrificial template, polyimide (PI) nanofibers are directionally interconnected by chemical pre-anchoring and heat treatment, which endows the three-dimensional fiber network with good structural stability. These directly assembled nanofiber aerogels exhibit an adjustable low-density range (12.3–31.5 mg/cm3), excellent compressive resilience and fatigue resistance (with only 7.2% permanent deformation after 100 cycles at 60% strain), demonstrating good shape recovery. Moreover, the complex nanofiber pathway and porous network structure contribute to superior thermal insulation performance with low thermal conductivity (28.5–31.8 mW m−1 K−1). Furthermore, the incorporation of polyimide and silica (SiO2) imparts these hybrid aerogels with remarkable high-temperature resistance and flame retardancy. This study introduces and validates a novel approach for obtaining superelastic and lightweight aerogels, highlighting its promising potential in the realm of high-temperature thermal insulation.