Imam Malik رحمه الله gave a great example when he was asked who is able to give fatawa and the Imam said,
Issuing fatwâ is not allowed except for a person who knows what the people have differed in. It was said, ‘Do you mean the different views of the people of opinions (those who depend more on analogy and speculation)? He replied, “No, [I mean] the different views of the Companions of Muhammad – Allâh’s praise and peace be upon him. And he must also know the textual evidence that abrogates [other rulings] and that which is abrogated [by other texts], both in the Quran and the hadîth of Allah’s Messenger – Allâh’s praise and peace be upon him. Such a person can issue fatâwâ.
Ibn ‘Abd Al-Barr, Jâmi’ Bayân Al-’Ilm wa Fadlihî article 1529.
And from the saying of Al Mubarak رحمه الله
It is reported that ‘Abdullâh b. Al-Mubârak – Allâh have mercy on him – was asked, “When can a person issue an edict (fatwâ)?” He replied, “When he is knowledgeable about the narrations (hadith and traditions of the Salaf), and has insight into [juristic] opinion.
Ibid. article 1532.