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."
حدثنا أبو كريب قال حدثنا عبد الله بن إدريس وعبدة وأبو معاوية وعبد الله بن نمير ومحمد بن بشر ح و حدثنا سويد بن سعيد قال حدثنا علي بن مسهر ومالك بن أنس وحفص بن ميسرة وشعيب بن إسحق عن هشام بن عروة عن أبيه
أن رسول الله ﷺ قال إن الله لا يقبض العلم انتزاعا ينتزعه من الناس ولكن يقبض العلم بقبض العلماء فإذا لم يبق عالما اتخذ الناس رءوسا جهالا فسئلوا فأفتوا بغير علم فضلوا وأضلوا
Bukhari narrated it in the Book of Knowledge, Chapter on How Knowledge Is Taken Away, hadith no. 100, and Muslim in the Book of Knowledge, Chapter on the Removal and Withdrawal of Knowledge... etc, hadith no. 2673, from the hadith of Hisham with this wording, and Abu Aswad followed him in both of their books. The wording of Bukhari in the Book of Holding Fast, Chapter on What Is Mentioned Regarding the Condemnation of Personal Opinion and Undue Reliance on Analogy, hadith no. 7307, is, "So they give rulings based on their own opinions, thereby going astray and leading others astray... etc."