The mausoleum of Imam Abu ʿAbdillah Muhammad ibn Idris al-Shafi‘i (d. 204H)(rahimahullah) has been, by the grace of Allah, for centuries one of the most prestigious and famous places of visitations by Sunni Muslims. Imam Shams ad-Din al-Jazari (d. 833H), one of the students of Imam Ibn al-Kathir, writes in his book “Tabaqat al-Qurra” ((طبقات القراء جلد2 صفحه87 )):
وقبره بقرافة مصر مشهور والدعاء عنده مستجاب ولما زرته قلت
زرت الإمام الشافعي لأن ذلك نافعي
لنال منه شفاعة أكرم به من شافع
that his grave at Qarafa in Egypt is famous, and duas made there are answered and when he visited him he read the above mentioned couplets seeking his intercession.
Imam al-Nawawi (d. 676H), in his book Sharh al-Muhadhdhab (المجموع شرح المهذب) writes about the mausoleum of al-Shafi:
وَقَبْرُهُ رَضِيَ اللَّهُ عَنْهُ بِمِصْرَ عَلَيْهِ مِنْ الْجَلَالَةِ وَلَهُ مِنْ الِاحْتِرَامِ مَا هُوَ لَائِقٌ بِمَنْصِبِ ذَلِكَ الْإِمَامِ.
that his tomb is in Egypt, and that its majesty/grandeur and esteem is one that befits the position of Imam al-Shafi.
Some secular writers have theorized that the mausoleum of Imam al-Shafi (may Allah have mercy on him) was first built by Salah ad-Din Ayyubi (may Allah have mercy on him) to compete with the Shiites/Fatimids. They assume that such structures did not exist prior to that or that it was evolved into Sunnism from the Shiites. Not surprisingly the Wahhabiyya pick on such theories to attack these structures.
Contrary to such assumptions, Imam Ibn ‘Abd Barr (d. 463H), the maliki jurist & theologian, who died about 60 years before Salah ad-Din was even born, records in his book الانتقاء في فضائل الثلاثة الأئمة الفقهاء (“The Hand-Picked Excellent Merits of the Three Great Jurisprudent Imâms”), in his biographical entry on Ibn ‘Abdal Hakam (d. 257H), that:
وَعِنْدَهُ مَاتَ الشَّافِعِيُّ وَدُفِنَ فِي وَسَطِ قُبُورِ بَنِي عَبْدِ الْحَكِم بِمِصْرَ وَبَنَوْا عَلَى قَبْرِهِ قُبَّةً
“al-Shafi died, he was buried in between the graves of the sons of Ibn Abd al-Hakam in Misr (Egypt) and a dome was built over his grave“
Its clear that not only was the structure over his grave existing prior to Salah ad-Din but shows also a dome being built during the 2nd century (of Islamic calendar) itself at the time of Ibn ‘Abd al Hakam in whose land Imam al-Shafi’s resting place lie.
As for what was built during the time of Salah ad-Din Ayyubi, he renovated the structure and constructed a madrassa alongside it. The madrassa ofcourse belonging to Asharis/Sufis, as mentioned on the following inscriptions on the madrassa:
Ibn Jubayr, who visited it in 1182–83, writes:
Allah Most Gracious has allowed the preservation and honor of the mausoleum of Imam Shafi to remain till today. May Allah continue to preserve it and protect it from the plots of the horns of Shaytan.