Sources of Islamic legislation
Question

What are the sources of Islamic legislation?.
Praise be to Allah.The sources of Islam on which all beliefs, principles and rulings are based are represented by the two Revelations: the Quran and Sunnah. This is what is implied by Islam being a divinely-revealed religion: its pillars are based on infallible texts that were sent down from heaven, which are represented in the verses of the Holy Quran and the texts of the saheeh Prophetic Sunnah. 
Imam al-Shaafa’i (may Allah have mercy on him) said: 
No view is binding unless it is based on the Book of Allah or the Sunnah of His Messenger (peace and blessings of Allah be upon him). Everything other than them should be based on them."(Jimaa’ al-‘Ilm). 
From these two sources the scholars derived other principles on which rulings may be based. Some scholars called them the sources of sharee’ah or the sources of Islamic legislation. They are: ijmaa’ (scholarly consensus) and qiyaas (analogy). 
Imam al-Shaafa’i (may Allah have mercy on him) said: No one has any right whatsoever to say that something is halaal or haraam except on the basis of knowledge, and the basis of knowledge is a text in the Quran or Sunnah, or ijmaa’ (scholarly consensus) or qiyaas (analogy)."(Al-Risaalah  39). 
Ibn Taymiyah (may Allah have mercy on him) said: 
If we say Quran, Sunnah and ijmaa’, they all stem from the same source, because the Messenger agrees with everything that is in the Quran, and the ummah is unanimously agreed upon it in general. There is no one among the believers who does not believe it is obligatory to follow the Book. And everything that the Prophet enjoined in his Sunnah, the Quran obliged us to follow it. So the believers are unanimously agreed upon that, and everything on which the Muslims are unanimously agreed can only be true and in accordance with what is in the Quran and Sunnah."(Majmoo’ al-Fatawa 7/40). 
Dr. ‘Abd al-Kareem Zaydaan said: 
What is meant by the sources of fiqh is the evidence from which it is derived and on which it is based. If you wish, you may say: The sources from which it is derived. Some people call these sources the “sources of sharee’ah” or “the sources of Islamic legislation.” No matter what they are called, the sources of fiqh all derive from the Revelation (wahy) of Allah, whether it is Quran or Sunnah. Hence we prefer to divide these sources into original sources, namely the Quran and Sunnah, and secondary sources to which the texts of the Quran and Sunnah refer, such as ijmaa’ (scholarly consensus) and qiyaas (analogy). End quote. 
Al-Madkhil li Diraasat al-Sharee’ah al-Islamiyyah (p. 153). 
With regard to sources other than these four, such as the opinions of the Sahaabah, istihsaan (discretion), sadd al-dharaa’i’ (blocking the means that lead to evil), istishaab, ‘urf (custom), the laws of those who came before us, al-masaalih al-mursalah (things that serve the general interests of the Muslims) and so on, the scholars differed as to how valid it is to use them as evidence. According to the view that they are acceptable – all or some of them – they are secondary to the Quran and Sunnah and should be in accordance with them. 
And Allah knows best.