An Outline of the History of Restriction on Ijtihad
This is also clear from what al-Maqrizi says following his above mentioned remarks: "Then, during the reign of Baybars al-Bunduqdari, four judges were appointed in Egypt: a Shafi'i, a Maliki, a Hanafi and a Hanbali." 
[Beginnings of Restriction of the Madhahib to Four:]
From the appointment of a separate qadi for each madhhab during the reign of al-Bunduqdari, who came to power on 17th Dhu at-Qa'dah 658/1259 and died in 676/1277, it appears that official status was accorded for the first time to all the four madhahib in Egypt during this period. Before him, the Hanafi and Hanbali schools were not officially recognized in this manner. Al-Maqrizi observes in this context.
This, i.e. the assumption of the office of judgeship by four-continued from 665/1266 until the time when there remained no other madhhab except these four in all Islamic towns that was counted among the madhahib of Islam. Anyone who followed any other madhhab was regarded with hostility, disowned and barred from judicial posts. The testimony of a person was not accepted unless he was a muqallid of one of these four schools. Throughout this period the fuqaha' of these madhahib issued decrees in these towns ruling that it was obligatory to follow these madhahib and unlawful to adhere to any other madhhab. This practice continues to this day. 
Our citation from al-Maqrizi's observations ends here, and from it the following conclusions may be drawn:
1. As pointed out earlier, the impact of the causes and factors in the propagation of the four madhahib was decisive, considering that these madhahib had totally disappeared from Egypt after 358/968 for years on during the era of the Fatimid caliphs. But later they were revived after their disappearance in 567/1171 and were then jointly accorded official recognition in 665/11266 which state continued until 804/1401 when alKhutat was compiled.
The causes affecting the course and continuity of the four madhahib were stronger, and hence their growth and advancement. The other schools retreated till they became gradually extinct after 665/1266.
2. Around the year 665 some unsightly and scandalous things were associated with Islam and enormities were committed in the name of religion. This was despite the fact that the Lawgiver had based the laws of Islam on harmony and accord amongst Muslims. He had instituted congregations and gatherings to promote the spirit of unity calling the people to mutual love and friendship, ordering them to cooperate with one another in every positive matter and binding Muslims together with the firmest bond ('urwat al-wuthqa) of brotherhood so that they would not disperse and remain united against others.
It is regrettable that at this time mutual hostility amongst Muslims was made a part of religion. Consequently the patrons of the four madhahib started to show hostility towards the followers of other schools, who like them pronounced the shahadatayn, prayed facing the Holy Ka'bah, performed Hajj, sought spiritual purification, and performed all obligatory and supererogatory acts which had reached them from the Prophet of Islam through authentic chains of transmission.
Someone might remark that this is not the first crisis in Islamic history. One might recall that which the pages of history disclose-specially those like the Kamil of Ibn al-Athir-concerning the battles and disturbances which took place in the preceding centuries amongst the Muslims, especially the conflicts that occurred in Baghdad and other cities between the followers of the four madhahib themselves (some of which we shall mention shortly) and between them and other Muslims.