The biomineralization process endows biominerals with unique hierarchically porous structures and physical–chemical properties by filling the restricted microreaction space with amorphous phases before the growth of inorganic crystals. In this paper, a confined-space fabrication method inspired by biomineralization for preparing hierarchically porous polyimide (PI) aerogels and PI-derived carbon aerogels is introduced. The confined structure is established through a self-assembly method of vacuum impregnation and ultrasound-assisted freeze-drying. The hierarchically porous structure is controlled by adjusting the structure characteristics of the confined space and secondary aerogels. Subsequently, a variety of performance demonstrations are conducted to demonstrate the mechanical properties and application prospects in the fields of thermal insulation and electromagnetic shielding of the prepared aerogel.