It is in Hadithes and Quran. Quoting from Al-Kafi, Book 1, chapters 22 and 23:
H 554, Ch. 22, h 1
A number of our people has narrated from Ahmad ibn Muhammad from al-Husayn ibn Sa‘id from an-Nadr ibn Suwayd from Ayyub ibn Hurr and ‘Imran ibn Ali from abu Basir from abu ‘Abdallah (a.s.) who has said the following. "We are the people well-grounded in knowledge and we are the ones who know how to interpret it."
H 555, Ch. 22, h 2
Ali ibn Muhammad has narrated from ‘Abdallah ibn Ali from Ibrahim ibn Ishaq from ‘Adallah ibn Hammad from Burayd ibn Mu‘awiya who has narrated the following from either one of the Imams (a.s.) about the words of Allah, Allah, the Most Majestic, the Most gracious. "No one knows its true interpretations except God and those who have a firm grounding in knowledge . . ." (3:7). The Holy Prophet is the best among the people well-grounded in knowledge. Allah, the Most Majestic, the Most gracious, taught him all that He had revealed to him in the form of original text and in the form of interpretations. Allah, the Most Majestic, the Most gracious, would not reveal anything to him that he would not know the meaning thereof. The successors of the Holy Prophet (s.a.) after him knew all revelations.
As for those who do not know the interpretations thereof, when the scholar speaks to them with knowledge, they say, "We believe in it, for all of this is from our Lord." The Holy Quran consists of specific, general, clear, not so clear, abrogating and abrogated statements. The people who are well-grounded in knowledge know all of the Holy Quran."
H 556ch22, h 3
Al-Husayn ibn Muhammad has narrated from MuAlia ibn Muhammad from Muhammad ibn ’Uwarma from Ali ibn Hassan from ‘Abd al-Rahman ibn Kathir from abu ‘bdallah (a.s.) who has said the following. "People well grounded in Knowledge stands for Amir alMu’minin Ali (a.s.) and the Imams after him."
H 557, Ch. 23, h 1
Ahmad ibn Mahran has narrated from Muhammad ibn Ali from Hammed ibn 'Isa from al-Husayn ibn al-Mukhtar from abu Basir who has said that he heard abu ‘Abdallah (a.s.) say the following about this verse of the Holy Quran. "In fact, the Quran consists of illustrious verses that exist in the hearts of those who have knowledge. . . ." (29:49) The Imams (a.s.) pointed to his own hear."
H 558, Ch. 23, h 2
It is narrated from him from Muhammad ibn Ali from ibn Mahbub from ‘Abd al-‘Aziz al-‘Abdi from abu ‘Abdallah (a.s.) who has said the following about the words of Allah, the Most Holy, the Most High. "In fact, the Quran consists of illustrious verses that exist in the hearts of those who have knowledge. . . ." (29:49) ‘They are the Imams (a.s.)’.
H 559, Ch. 23, h 3
It is narrated from him from Muhammad ibn Ali from 'Uthman ibn ‘Isa from Sama‘a from abu Basir from abu Ja‘far (a.s.) who has said the following about this verse of the Holy Quran. "In fact, the Quran consists of illustrious verses that exist in the hearts of those who have knowledge. . . ." (29:49) The Imams (a.s.) then said, "O abu Muhammad, for the sake of Allah, be the judge and tell, of who it is spoken (so often) between the two covers of the Holy Quran?" I then asked, "Who are they, "May Allah take my soul in service for your cause. The Imams (a.s.) said, "Who else can they be other than ourselves?"
H 560, Ch. 23, h 4
Muhammad ibn Yahya has narrated from Muhammad ibn al-Husayn from Yazid Sha‘ar from Harun ibn Hamza who has said that he hear abu ‘Abdallah (a.s.) say who has said the following. "In fact, the Quran consists of illustrious verses that exist in the hearts of those
who have knowledge. . . ." (29:49) ‘They are the Imams (a.s.) exclusive of all others.’"
So, according to these verses and Hadithes, only the Prophet and the Successors (Shia imams) are well-grounded in knowledge and know all its interpretation. Allah said, He only purified people of the Household. So, their Heart is pure and clean, and they would have a perfect understanding, because according to Quran, with Heart we understand, and when they were purified, and had a pure heart, they had perfect understanding.