Abdullah bin Amr bin As reported,

The Messenger of Allah ﷺ said, "Allah does not take away knowledge by snatching it from people, but He takes it away by taking the scholars. When no scholar remains, people will take ignorant ones as their leaders. They will be asked questions and will issue rulings without knowledge, so they will go astray and lead others astray."

Ibn Majah 52

Sahih

حدثنا أبو كريب قال حدثنا عبد الله بن إدريس وعبدة وأبو معاوية وعبد الله بن نمير ومحمد بن بشر ح و حدثنا سويد بن سعيد قال حدثنا علي بن مسهر ومالك بن أنس وحفص بن ميسرة وشعيب بن إسحق عن هشام بن عروة عن أبيه

عن عبد الله بن عمرو بن العاص

أن رسول الله ﷺ قال إن الله لا يقبض العلم انتزاعا ينتزعه من الناس ولكن يقبض العلم بقبض العلماء فإذا لم يبق عالما اتخذ الناس رءوسا جهالا فسئلوا فأفتوا بغير علم فضلوا وأضلوا

ابن ماجه 52صحيح
Contents
Reference
Commentary
Ayat
Collection
Sunan Ibn Majah
Book
Sunnah
Chapter
Avoiding opinion and analogy
Numbering
Darussalam 52
Ibn Majah 52