Al-Kāfi - Volume 1 > Chapter on the quality of knowledge its virtue and the virtue of the scholars
Hadith #3

3ـ الْحُسَيْنُ بْنُ مُحَمَّدٍ عَنْ مُعَلَّى بْنِ مُحَمَّدٍ عَنِ الْحَسَنِ بْنِ عَلِيٍّ الْوَشَّاءِ عَنْ حَمَّادِ بْنِ عُثْمَانَ عَنْ أَبِي عَبْدِ الله (عَلَيْهِ السَّلام) قَالَ إِذَا أَرَادَ الله بِعَبْدٍ خَيْراً فَقَّهَهُ فِي الدِّينِ.

3. Al-Hassan ibn Muhammad has narrated from Mu‘alla ibn Muhammad from al-Hassan ibn Ali al-Washsha’ from Hammad ibn ‘Uthman from abu ‘Abdallah (a.s.) who has said the following. “When Allah wants goodness for a person He gives him (Fiqh) good understanding of religion.”