First to know is that there are levels for Mujtahids, what we are talking about here is the "Unlimited Mujtahid" (Mujtahid Motlak المجتهد المطلق), which is the highest level.
There is a quote of Imam Shafei (may Allah be merciful to his majesty) that describes who can derive fatwas, i.e, who is a qualified mujtahid:
قال الشافعي: لا يحل لأحد أن يفتي في دين الله إلا رجلاً عارفاً بكتاب
الله: بناسخه ومنسوخه، وبمحكمه ومتشابهه، وتأويله وتنزيله، ومكيّه
ومدنيّه، وما أريد به، وفيما أنزل، ثم يكون بعد ذاك بصيراً بحديث رسول
الله بالناسخ والمنسوخ، ويعرف من الحديث ما عرف من القرآن، ويكون بصيراً
باللغة، بصيرا بالشعر، وبما يحتاج إليه للعلم والقرآن، ويستعمل مع هذا
الإنصاف، وقلة الكلام ، ويكون بعد هذا مشرفاً على اختلاف أهل الأمصار،
وتكون له قريحة بعد هذا، فإذا كان هكذا فله أن يتكلم ويفتي في الحلال
والحرام، وإذا لم يكن هكذا فله أن يتكلم في العلم ولا يفتي.
Shafei said: Nobody is permitted to give fatwas in Islam except a person who is
knowlegeable in Quran: what's abolishing and abolished, what's Mohkam مُحكَم [clear,
precise, decisive, entirely clear, categorical, firmly constructed,
lucid, obscure] and Motashabeh مُتشابِه [unclear, unspecific, cosimilar, ambiguous,
allegorical, not entirely clear, indistinct], it's [Explanation,
interpretation] and revelation, what's Makki
or Madani, what was meant by it and why it was revealed [Story of
revelation أسباب النزول], and then he should be experienced (skilled)
in Hadith: what's abolishing and abolished, and know about
Hadith like what he knows about Quran. Then he should be skilled in
(Fusha Arabic) language: skilled in poetry, and whatever he needs in
(Islamic) science (knowledge) and Quran. Besides he have to use
justice, and not to be talkative (or have to be a man of
few words). Then he have to be aware of the differences among people
in countries. And have to have the talent, after all that. If he had
all that then he is permitted to give fatwas and talk about halal and
haraam, and if he doesn't have all that then he can speak (discuss) in
(Islamic) sciene but is not permitted to give fatwas.
Al-Faqieh wa Al-Motafaqeh by Al-Khabeeb Al-Baghdadi, vol.2, pages
157-158. Similar quotes of Imam Shafei can be found in his book Al-Um الأم vol.7, pages 274 and later.
الفقيه والمتفقه للخطيب البغدادي، ج2 ص157-158
Online citations can be found here and here.
So, Imam Shafei (may Allah be merciful to his majesty) has well-declared the qualifications that are required in Mujtahid in this quote and other quotes, in summary to all quotes they are:
Knowledge of Quran science: many of it's fields, this doesn't mean that he have to be memorizing the whole quran, this is not obligatory but is preferred. What's important is to know what Quran contains, what Ayas of Ahkam (rules) are there (but not necessarily memorize them) and where are they, in other words, he have to be "flexible" in Quran. Also he have to have knowledge in many Quran science fields, such as (there are many others required):
- Abolishing and Abolished: a short description of this is that there are some Ayat that were revealed and included rules, but then Allah revealed other Ayat that overwrites the rules of the previous ones (there are reasons why Allah may do this, and the reasoning is part of this Quran science field itself), the previous ones may be omitted from Quran, and may not (still exist yet not a valid ruling source).
- Muhkam and Mutashabeh: there are clear Ayat in Quran that cannot bear more than one meaning, on the other hand, there are Ayat that are not entirely clear, or can bear more than one meaning, or are ambiguous and only Allah knows their meanings (such as الم and كهيعص).
- I won't mention other fields, yet there are others.
Knowledge of Sunnah (Hadith) science: many of it's fields, and, as mentioned in the quote, he should have knowledge of the same fields in Hadith that are required to know in Quran. For example he should be "flexible" in Hadith, which means knowing what hadiths there are, what's sahih and what's weak and what's fabricated (موضوع), the history of men (who narrat hadith) and how trustworthy they're, in fact there are many things required, I cannot mention here.
Knowledge of (Fusha) Arabic Language: especially poetry because it's the source from which word meanings and rhetoric and be learned, this is important mainly because Quran is very eloquent (the most), and The Prophet (PBUH) is very eloquent as well. So if one is to really understand Quran in Hadith, he definitely have to be reasonably good (but not expert) in Arabic Language, all of it's fields: rhetoric, grammar.. etc.
Justice and Fairness: This is obviously required, otherwise his fatwa wouldn't be acceptable if he is not justice, as he would direct it according to his own will.
Knowledge of Ijmaa': This means he should now what scholars have agreed on so that he doesn't violate agreement (as agreement is more preferred than difference in opinions in Fiqh). And as a requirement, he should also know what previous scholars mathahib were, and what they said, what's their reasons, and Usool al Fiqh (but doesn't have to know Foroo' al Fiqh).
Knowing differences among people (communities), in other words, knowing the specifications of each (muslim) community (of course not all of them, just what he needs in the case he is giving fatwa in), in fact sometimes fatwas differ according to the place where the Mujtahid gives it, because of necessity, conventions, and other reasons.
Talent: it's like when one is very skilled in dealing with numbers and can give hard answers without even thinking. Ali Jum'a (Mufti of Egypt) says:
ومعني ذلك أن يكون كثير الإصابة صحيح الاستنباط وهذا يحتاج إلى حُسن
التصور للمسائل وبقدر ما يستطيع المجتهد أن يتخيل المسائل بقدر ما يعلو
اجتهاده ويفوق أقرانه فهو يشبه ما يعرف في دراسات علم النفس بالتصور
المبدع.
It means he mostly give right answers (and opinions), and he devises
(derives) correctly, this requires good conception and imagination for
the problem, the more the mujtahid is good at conception and
imagination, the more his Ijtihad is superior to his peers, it's just
like what's known as "creative imagination" in the psychology.
Other things like being Muslim (obviously), not being talkative (in fact this is because wise people can say what they want in few words, unlike others), being a good man and not known to do prohibited things, being adult (i.e, pubescent), being reasonable.
It deserves mention that there are things that doesn't have to be in a Mujtahid (while people think they should be in him), like:
Doesn't have to be a man, a woman (that has the above qualifications) can be Mujtahid.
Doesn't have to be a free man, a slave (that has the above qualifications) can be Mujtahid.
Sources:
Hope that's helpful, and hope I could make it clear enough and didn't make any mistake collecting them and didn't miss anything, if anything is wrong, I's much appreciate to edit and correct.