I heard the Messenger of Allah ﷺ say, "Allah does not take away knowledge by snatching it from the people, but He takes away knowledge by taking the souls of the scholars, until when no scholar remains, the people take ignorant leaders. They are asked, and they give rulings without knowledge, so they go astray and lead others astray."
حدثني يحيى عن هشام أملاه علينا حدثني أبي سمعت
سمعت رسول الله ﷺ يقول إن الله لا يقبض العلم انتزاعا ينتزعه من الناس ولكن يقبض العلم بقبض العلماء حتى إذا لم يترك عالما اتخذ الناس رؤساء جهالا فسئلوا فأفتوا بغير علم فضلوا وأضلوا
Its isnad is sahih. Hisham is Ibn Urwa bin Zubayr. The hadith was narrated by Bukhari 1:174–175 and 13:239–242, Muslim 2:305–306, and Tirmidhi 3:371, who said it is a hasan sahih hadith, and Ibn Majah 1:14, Darimi 1:77, and Tayalisi 2297. Ibn Abdul-Barr also narrated it in Jami Bayan Ilm 1:148–151 through numerous chains. Hafiz gave it a thorough explanation in Fath al-Bari 13:239–242, and pointed to many of its routes and versions.