The Ayyubids, who inherited the Seljuq and Zengid legacy of endorsing Sunnism and abolishing all signs of heterodoxy, particularly the Isma'ili doctrine of the Fatimids, used the institution of the madrasa to propagate and disseminate the Sunni law and teachings.
Saladin founded a madrasa dedicated to the Shafi'i rite near the tomb of the founder of the rite, Imam al-Shafi'i, who was buried in the Lesser Qarafa of the Southern Cemetery in 820. At his behest a cenotaph, a magnificent piece of Islamic woodwork built of teak imported from India, was placed over the grave of the Imam. It was carved by 'Ubayd al-Najjar ibn Ma'ali in 1178-9. The mausoleum, with a wooden dome over the grave, was erected in 1211 by al-Malik al-Kamil, whose grave, along with his mother's, is also under this dome and a few steps away from the Imam's.
It is the first officially sponsored mausoleum to be built for a Sunni theologian after the extinguishing of the Isma'ili Fatimids in 1171. It is also the largest detached mausoleum in Egypt. Paradoxically, the Fatimid practice of building domed mausolea for 'Alid saints as a means of promoting their Shi'i agenda and gathering popular support for the Fatimid imams was adopted by the same leaders who eradicated all signs of Shi'ism in Egypt. In fact, this mausoleum is regarded as the symbol of the triumph of orthodoxy over heterodoxy.
Restorations by Sultan Qaytbay included the addition of the marble dado, and the rebuilding of the dome, with its wooden muqarnas squinches. One of the window (or door) recesses is roofed by a ceiling comprising octagonal coffers dating from the construction of al-Kamil (1211) and believed to be the first of their kind in Egypt.
The second rectangular, receding story of the exterior, behind which is the transitional zone of the dome, is adorned with keel-arched niches crowned with fluted shell-hoods. The "post and panel" parapet at the summit of the lower part of the exterior, also dating from 1211, displays interlaced geometrical patterns which are analogous to those employed above late Fatimid prayer niches. Each of the posts is adorned with one of two designs carved in stucco. The first is a Maghribi or Andalusian pattern consisting of Kufic on an arabesque background; the second is a floral arabesque pattern.
The current dome, which dates from the restoration of 'Ali Bey al Kabir (1772), comprises two wooden shells covered with lead, a construction recalling that of the Dome of the Rock in Jerusalem. Also from the restoration of 'Ali Bey al Kabir are the painted inscriptions of the interior as well as the painted decoration of the walls, muqarnas squinches, and dome. To 'Abd al Rahman Katkhuda is attributed the polychrome pavement in the entrance vestibule.