How did Islamic fiqh develop?
Question

how was the science of fiqh developed ?
Praise be to Allah.During the lifetime of the Prophet (peace and blessings of Allaah be upon him) the Muslims used to receive the rulings of Islam directly from him. The Qur’aan came down as a teacher, guide and mufti, as Allaah said (interpretation of the meaning): 
“They ask you for a legal verdict. Say: “Allaah directs (thus) about Al-Kalaalah (those who leave neither descendants nor ascendants as heirs)…”[al-Nisa’ 4:176]
 And it came to explain matters concerning which the Prophet (peace and blessings of Allaah be upon him) and his companions were uncertain, as in the story of the woman who asked the Prophet (peace and blessings of Allaah be upon him) about her husband’s divorcing her by zihaar (a jaahili form of divorce in which the husband says to his wife, “You are to me as my mother’s back”), as a result of which the first verses of Soorat al-Mujaadilah were revealed. 
The Prophet (peace and blessings of Allaah be upon him) used to send some of his companions to teach the new Muslims how to worship and to give them legal rulings (fatwa). The Prophet (peace and blessings of Allaah be upon him) used to allow them a certain amount of room in understanding the texts of sharee’ah, then he would approve of their interpretation or correct them. At the time of the Prophet (peace and blessings of Allaah be upon him) a number of the Sahaabah used to issue fatwas (legal rulings). Some of the scholars said that they numbered fourteen, but in fact there were more than that. The Prophet (peace and blessings of Allaah be upon him) was the imaam (leader) and teacher of mankind and at that time people spoke proper Arabic so whatever variations in interpretation there were, were few and minor. So the death of the Prophet (peace and blessings of Allaah be upon him) was counted as a great loss to the ummah, because they lost their leader, guide and perfect example. 
It was narrated that Anas ibn Maalik said: “After the death of the Messenger of Allaah (peace and blessings of Allaah be upon him), Abu Bakr said to ‘Umar, ‘Let us go to Umm Ayman and visit her as the Messenger of Allaah (peace and blessings of Allaah be upon him) used to do. When they came to her, she wept, and they said to her, ‘Why are you weeping? What is with Allaah is better for His Messenger (peace and blessings of Allaah be upon him).’ She said, ‘I am not weeping because I do not know that what is with Allaah is better for His Messenger (peace and blessings of Allaah be upon him); rather I am weeping because the revelation from heaven has come to an end.’ She moved them to tears and they started weeping with her.” (Narrated by Muslim, 2454). But the Prophet (peace and blessings of Allaah be upon him) did not die until after the religion had been completed. 
One of the characteristics of this religion, which was perfected during the time of the Prophet (peace and blessings of Allaah be upon him), was that it includes features which qualify it to remain and continue until the end of time. 
Therefore this religion and understanding of it remained after the death of the Prophet (peace and blessings of Allaah be upon him) and it will abide until the Day of Resurrection. After the death of the Prophet (peace and blessings of Allaah be upon him), the people followed his guidance and the guidance of the Rightly-Guided khaleefahs who followed him. Abu Bakr (may Allaah be pleased with him) used to judge amongst them and issue fatwas to them based on what he found in the Qur’aan and hadeeth. If he could not find an answer, he would go out and ask the Muslims, saying, “Such and such an issue has been referred to me, do you know whether the Messenger of Allaah (peace and blessings of Allaah be upon him) passed a judgement concerning such a matter?” Then perhaps a group of them would come to him, all of them saying that the Messenger of Allaah (peace and blessings of Allaah be upon him) had passed a judgement on it. Then Abu Bakr would say, “Praise be to Allaah Who has caused there to be among us those who memorized things from our Prophet.” And if he was unable to find any Sunnah narrated from the Messenger of Allaah (peace and blessings of Allaah be upon him), he would gather the leaders of the people and the best among them and if they agreed on something he would pass judgement according to that. 
‘Umar (may Allaah be pleased with him) did the same after Abu Bakr had died. 
Then the Sahaabah (may Allaah be pleased with them) dispersed to different regions as teachers and mujaahideen, after the expansion of the Islamic territory. Each of them used to issue fatwas in accordance with what he knew of the Qur’aan and Sunnah, or the actions of Abu Bakr or ‘Umar, or the conclusions to which his own ijtihaad led him. The muftis among the Sahaabah numbered more than one hundred, and those who issued many fatwas numbered seven, as Ibn al-Qayyim says. They were: ‘Umar ibn al-Khattaab, ‘Ali ibn Abi Taalib, ‘Abd-Allaah ibn Mas’ood, ‘Aa’ishah Umm al-Mu’mineen, Zayd ibn Thaabit, ‘Abd-Allaah ibn ‘Abbaas and ‘Abd-Allaah ibn ‘Umar (may Allaah be pleased with them all). 
‘Umar (may Allaah be pleased with him) and his son, and Zayd ibn Thaabit (may Allaah be pleased with them), were in Madeenah, and many students became scholars at their hands,  such as Saalim ibn ‘Abd-Allaah ibn ‘Umar, Naafi’ and others. Their knowledge was passed to the seven fuqaha’ and ultimately to Imaam Maalik ibn Anas al-Asbahi. 
Ibn Mas’ood and then ‘Ali were in Kufa, and a number of the Taabi’een learned from them, such as ‘Ilqimah, al-Aswad, Masrooq, Shurayh al-Qaadi, Silah ibn Zafar and many others besides them, until that knowledge reached Imaam Abu Haneefah al-Nu’maan ibn Thaabit. 
Fiqh and knowledge spread throughout the ummah from the companions of Ibn Mas’ood, the companions of Zayd ibn Thaabit, the companions of ‘Abd-Allaah ibn ‘Umar, and the companions of ‘Abd-Allaah ibn ‘Abbaas. That happened in Kufa, Madeenah and Makkah, respectively. These Taabi’een used to issue fatwas when the greatest Sahaabah were present, and they granted them permission to do that.  
For example, Ibn ‘Umar used to say of Sa’eed ibn al-Musayyib: he is one of the muftis or one of those to be followed. 
And he said of him: if the Prophet (peace and blessings of Allaah be upon him) had seen him, he would have been happy with him. 
Via these people, knowledge spread far and wide. Then the ahaadeeth were compiled in books and the numbers of students increased who occupied themselves with memorizing them and writing them down; then knowledge spread throughout the earth. Most of the people were religiously-committed and aware, and this prevented anyone from speaking without knowledge or claiming to be a scholar when he was not qualified to describe himself as such. Then differences because widespread and people became involved in the field of knowledge who would have been better off refraining from it. But by the wisdom of Allaah the religion was regulated and preserved by imams whom the ummah agreed that they were leaders and knowledgeable and that they had reached the utmost degree of knowledge of rulings and fatwas. Allaah caused them to become well known and their virtue spread throughout the world. Students flocked to them to learn and study, and their views were compiled in books. The opinions of the Sunni schools of thought which followed the truth of the Qur’aan and Sunnah and which rejected innovations in religion (bid’ah), according to what was transmitted by the students of the great imams, were recorded according to what was transmitted by the students of these great scholars, so the views of each imaam became a madhhab that is followed. 
The most famous of these madhhabs nowadays are just four: the Hanafi, Maaliki, Shaafa’i and Hanbali madhhabs. The followers of these madhhabs are agreed on most matters and on the most important issues of religion, and the differences in understanding and in the evidence that reached them have to do with minor issues. All of them are following something good, may Allaah have mercy on them. Then each of these madhhabs developed in ways which it would take too long to explain here, until things became as they are nowadays, where each madhhab has books containing its issues and methods of deriving rulings and interpreting evidence. And among the imams there are, praise be to Allaah, mujtahids who can produce rulings on contemporary events and issues by means of the understanding that Allaah has bestowed upon them, using ijtihaad, qiyaas (analogy), the principles of the objectives of sharee’ah, the sayings of previous scholars, and the principles of usool al-fiqh. Thus fiqh continued to be a rich discipline, comprehending all the issues of life which the Muslims need to know about. 
At all times there is someone who is showing the correct way, based on evidence, who recognizes the truth concerning a certain issue and he knows how to reach the correct conclusion. The scholars could not agree on something that is incorrect, hence the ummah cannot all follow falsehood. We ask Allaah to cause us to understand His religion and to bless us with knowledge and righteous deeds. And Allaah knows best. 
For more information see: 
Al-Fikr al-Saami fi Taareekh al-Fiqh al-Islaami and Taareekh al-Fiqh al-Islami by ‘Umar ibn Sulaymaan al-Ashqar. 
And Allaah knows best.