The Ayyubid Dynasty was founded by Salah Ad-Din Al-Ayyubi who succeeded in ruling Egypt independently, and became the only real ruler after the death of the Caliph Al-A'ded the last Fatimid Caliph in 567 A.H, and Egypt returned under the Abbasid Caliphate once more.
Salah Ad-Din worked on spreading the Sunni doctrine instead of Shiism that was common in the Fatimid period. He built the citadel as a new seat of government to rule Egypt from, and he set part of it for residence.
The Ayyubid dynasty is a martial (military) state as it appeared while the Islamic world was facing a serious threat which is the Crusades on Egypt and Ash-sham.
The Ayyubid dynasty expanded to include Ash-sham, Hijaz, Yemen, Nubia, and parts of Morocco, the Ayyubid Reign stayed in Egypt for 81 years, and ended on the hands of the Mamelukes Emirs in 648 A.H/1250 A.D.