All perfect praise be to Allaah, The Lord of the worlds. I testify that there is none worthy of worship except Allaah and that Muhammad, sallallaahu ʻalayhi wa sallam, is His slave and Messenger.
Firstly, you should know that the ultimate objective of the four Imaams and other Muslim scholars was to produce a body of jurisprudence that conforms to the texts of the Quran and Sunnah. These Imaams may hold different views regarding certain juridical issues. Shaykhul-Islam Ibn Taymiyyah summarized the considerable reasons for the difference of opinion among scholars in his book Raf’ Al-Malaam ʻan Al-A'immah Al-Aʻlaam. Please, refer to fatwa 88391.
One of these reasons is the fact that some of these Imaams may have been unaware of certain ahaadeeth of the Prophet, sallallaahu ʻalayhi wa sallam, known to other scholars given the fact that the Companions dispersed throughout the Muslim world with the intention of spreading Islam and knowledge and teaching people what benefits them in their worldly life and Hereafter.
Imaam Ash-Shaafiʻi, for instance, grew up in Madeenah and later traveled to Baghdad and then Egypt. This helped him become more acquainted with the Sunnah of the Prophet, sallallaahu ʻalayhi wa sallam, modifying some of his statements on certain issues after settling in Egypt. Therefore, we have now the early/old and the later/new Shaafiʻi mathhab. (Ash-Shaafiʻi developed two schools of jurisprudence; one school was established in Iraq and is referred to as the 'old or early Shaafiʻi school'; when he moved to Egypt, stopping by Makkah, he met a number of scholars and narrators, and he retracted some of his earlier opinions that he held in Iraq. This is what became known as the 'new or later Shaafiʻi school'.) It is not strange then that most of the principles of the Shaafiʻi school conform with the Sunnah. However, this does not undermine the refined status and authoritative weight of the other schools of jurisprudence in any way. It should be noted that such remarks must not be made with the intention of belittling or undermining the status of the other schools of jurisprudence.
You can refer to the books on the history of Islamic legislation to learn more about the Islamic jurisprudence (Fiqh), the phases of its development and documentation, and the principles upon which the schools of Fiqh are founded.
Allaah knows best.