An Outline of the History of Restriction on Ijtihad
Ibn al-Fuwati's account confirms al-Maqrizi's statements, except that the latter's discussion was limited to Egypt. Hence, he mentions the official recognition granted to the four madhahib in Egypt and the decree which at one stroke made it obligatory to follow these madhahib and no other. This occurred during the reign of al-Bunduqdari when the four qadis were appointed in 665/1266. Before this they had no such kind of official recognition. However, Ibn al-Fuwati mentions the official recognition of the four madhahib in Baghdad, the seat of the caliphate and the centre of Islamdom, which took place in 631/1233, when the al-Mustansiriyyah college was inaugurated and divided into four wings assigned to the followers of the four madhahib. Though earlier no such restriction existed, in 645/1247 the teachers of the madrasah were ordered not to transcend the opinions of the early mashd'ikh, whose sanctity was to remain secure and the blessing of their precedence in learning and religion to be invoked.
Ibn al-Fuwati mentions the excuse which the fuqaha' submitted in declining to comply with the imposition to confine to one of the four madhahib and the proscription on others, making it clear that it was done on the order of the caliph and that they were coerced to accept it, as is made clear by [the initial resistance of] the Shafi'i and the Hanafi teachers. Al-Maqrizi, however, was not in Baghdad and was not aware of the caliph's imposition. Hence he does not mention it and ascribes the order to the fuqaha'. And if this excuse were not considered acceptable by the fuqaha', they would be deemed to have committed a mistake-as will be explained later-in limiting the madhahib to the four.
As to the caliphs, the basis of their directives was nothing except the exigencies of mundane politics, although they apparently based their decrees on the consent of the f uqaha' who assisted them in their objectives. For example, Ibn al-Salah 'Uthman ibn 'Abd al-Rahman ibn 'Uthman al-Shahruzi, the commentator of al-Wasit, a work on Shafi'i fiqh,
who was appointed a teacher at Dar al-Hadith by al-Malik al-Ashraf and died there in 643/1245, issued a fatwa that it was unlawful to follow any except the four Imams, citing as his basis the consensus of scholars, as mentioned by Muhammad Mustafa at-Maraghi, the shaykh of al-Azhar, on page 17 of al-Bahth fi al-tashri' al-Islami  ...al-ziwaj wa al-talaq. 
[Factors Responsible for Restricting the Number of Madhahib:]
The reason behind the limitation on the number of madhahib, mentioned by Ibn al-Fuwati and as disclosed by historical accounts, is one of these two:
First: The first of these is the one stated in the Riyad al-'ulama' in the biographical account of al-Sharif al-Murtada 'Alam al-Huda. After mentioning the Tahdhib al-ansab wa nihayat al-a'qab by the genealogist al-Sayyid Abu al-Hasan Muhammad ibn Muhammad ibn 'Ali ibn al-Hasan al-Husayni al-Musawi, the author observes: It is widely known among the 'ulama' that the Ahl al-Sunnah, during the reign of the caliphs, when they encountered such dispersion of madhahib on legal issues (furu' al-din) and divergence of opinions and tendencies that it was impossible to keep track of them-considering that each of the Sahabah, Tabi'un, and those who came after them, up to the period of these caliphs, had his own madhhab and personal views in regard to the issues of the Shari'ah and its practical laws-resorted to curtailing the madhahib and were compelled to dissolve most of them. Therefore, they concurred upon accepting some of them. 
Hence they selected the four madhahib due to the large number of their followers and their abundant wealth.
Second: The extensive and endless differences in opinions and views resulting from the practice of ijtihad forced the caliphs to reduce their number, and as they were incapable of setting aside some of these four madhahib in view of the extent of conflict it entailed and given the zealotry of their followers, they resorted to limiting the madhahib to the four.
The evidence of their inability to set aside any of the four madhahib is provided by al-Maqrizi in al-Khutat where he reports that when Abu Hamid al-Isfara'ini wrote to Sultan Mahmud ibn Subuktigin in 393/1002 that the caliph had transferred the control of the judiciary from the Hanafis to the Shafi'is, this led to such a great confrontation between the followers of the two schools that the caliph was forced to change his mind. He was indignant at Abu Hamid, but had to reinstate the Hanafis to their earlier position.