In The Name of Allaah, The Most Merciful, The Bestower of Mercy.
Abdur-Rahmaan Bin Abee Layla [rahimahullaah] said: I have met a hundred and twenty companions of the Messenger [sallal-laahu-alayhi-wasallam] in this Masjid and not a single one of them would be asked about a hadeeth, except he wished that his brother would suffice him in [answering]. Then the affair was assigned to a people who claimed knowledge at present. They give answers in affairs which if presented to Umar Ibnul Khattaab [radiyallaahu-anhu], he would have gathered the [Sahaabah of] Badr to consult them. [Sharhus Sunnah of Imaam Al-Baghawee: 1/305]
Imaam Shaafi’ee [rahimahullaah] said: “It is not permissible for anyone to give fatwa in Allaah’s Religion except a man who is knowledgeable about the Book of Allaah – (knowledgeable) about its Naasikh and Mansookh (i.e. the science of abrogating and abrogated related to verses of the Qur’aan); its Muhkam (i.e. the clear verses which the scholars who are firmly grounded in knowledge point out be from those that do not require explanation by other verses) and its Mutashaabih (i.e. the verses which the scholars who are firmly grounded in knowledge point out be ones that require elaboration and explanation through other verses); its (sound) interpretation; (knowledge about when an Ayah or Surah) was revealed- whether it is Makkiy or a Madaniy (i.e. the subject matter regarding how to determine that an Aayah or Surah was revealed in Makkah or Medeenah); what is intended by a verse and for which circumstances (or purpose) it was revealed. Thereafter, he should have sure knowledge about the hadeeth of the Messenger of Allaah (sallal-laahu-alayhi-wasallam) in relation to its Naasikh and Mansookh (i.e. the subject matter regarding the abrogating and abrogated ahaadeeth discussed by the scholars who are firmly grounded in knowledge), and he should know the affairs of the hadeeth in the manner in which he knows the Qur’aan. He should have sure knowledge about the Arabic language and Arabic poetry, and what is needed of it. Then he applies this (knowledge) alongside being a just person and one whose speech is little. He should be one who has the ability to adjudicate (or make sound judgements) on the differences of opinions held by the scholars of the different eras and he should be talented. If he is like this [i.e. if the upright scholars upon sound Aqeedah and Manhaj- those firmly grounded in knowledge-testify that he is qualified in all these fields], then he can speak and issue fatwa in affairs of halaal and haraam. But if he is not, then it is not for him to give fatwa”.
[Source: An Excerpt from I’laam Al-Muwaqqi’een 2/87. Publisher: Daar Ibn Al-Jawziyyah’ 1st ed 1423AH.slightly paraphrased]