Language:
كتاب الاعتصام بالكتاب والسنة
96  
Holding Fast to the Qur'an and Sunnah
(13)
Chapter: Exerting oneself to find out the proper legal verdict which is in harmony with what Allah has revealed
(13)
بَابُ مَا جَاءَ فِي اجْتِهَادِ الْقُضَاةِ بِمَا أَنْزَلَ اللَّهُ تَعَالَى
Sahih al-Bukhari 7316

Narrated `Abdullah:

Allah's Messenger (ﷺ) said, "Do not wish to be like anybody except in two cases: The case of a man whom Allah has given wealth and he spends it in the right way, and that of a man whom Allah has given religious wisdom (i.e., Qur'an and Sunna) and he gives his verdicts according to it and teaches it." (to others i.e., religious knowledge of Qur'an and Sunna (Prophet's Traditions)). "

حَدَّثَنَا شِهَابُ بْنُ عَبَّادٍ، حَدَّثَنَا إِبْرَاهِيمُ بْنُ حُمَيْدٍ، عَنْ إِسْمَاعِيلَ، عَنْ قَيْسٍ، عَنْ عَبْدِ اللَّهِ، قَالَ قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏ "‏ لاَ حَسَدَ إِلاَّ فِي اثْنَتَيْنِ رَجُلٌ آتَاهُ اللَّهُ مَالاً فَسُلِّطَ عَلَى هَلَكَتِهِ فِي الْحَقِّ، وَآخَرُ آتَاهُ اللَّهُ حِكْمَةً فَهْوَ يَقْضِي بِهَا وَيُعَلِّمُهَا ‏"‏‏.‏
Reference : Sahih al-Bukhari 7316
In-book reference : Book 96, Hadith 47
USC-MSA web (English) reference : Vol. 9, Book 92, Hadith 419
  (deprecated numbering scheme)