The Prophet ﷺ said, "Whoever enters this mosque of ours to learn something good or to teach it is like one striving in the path of Allah, and whoever enters it for any other purpose is like one gazing at something that does not belong to him."
عن النبي ﷺ: من دخل مسجدنا هذا ليتعلم خيرا، أو ليعلمه كان كالمجاهد في سبيل الله، ومن دخله لغير ذلك كان كالناظر إلى ما ليس له.
Imam Ahmad narrated it (8603, 10814), as did Ibn Majah (227), and Ibn Hibban graded it sahih (87), as did Hakim (1/91), all of them from the hadith of Abu Sakhr, from Saeed bin Abu Saeed Maqburi, from Abu Hurairah, and he related it. Its chain is hasan because of Abu Sakhr, who is Humayd bin Ziyad, about whom there is disagreement, though his hadith is hasan.Hakim said, "This is a sahih hadith meeting the criteria of the two Shaykhs, for they both relied on all its narrators, yet they did not include it, and I do not know of any defect in it." So he said, but Bukhari did not include Humayd bin Ziyad, rather only Muslim included him, though his hadith is hasan.Daraqutni was asked about this hadith and said, "There is disagreement about it regarding Saeed Maqburi. Abu Sakhr, Humayd bin Ziyad, narrated it from Saeed Maqburi, from Abu Hurairah, from the Prophet ﷺ. Ubaydullah bin Umar contradicted him, narrating it from Saeed Maqburi, from Umar bin Abu Bakr bin Abdul-Rahman bin Harith, from Kaab Ahbar as his own statement. And Ibn Ajlan narrated it from Saeed Maqburi, from Abu Bakr bin Abdul-Rahman, from Kaab Ahbar as his own statement, and the statement of Ubaydullah bin Umar is closer to being correct." End of quote.I say, Daraqutni's statement is stronger from the standpoint of the chain, but the ruling belongs to whoever adds something, for such a matter is not spoken by personal opinion, as is well known. Perhaps the successor himself narrated it in both ways, so neither version invalidates the other.As for what has been narrated from a number of companions, "Seek knowledge even as far as China, for seeking knowledge is an obligation upon every Muslim," none of it is established. Imam Ahmad said, "Nothing is established with us on this subject." Ishaq bin Rahawayh said, "Seeking knowledge is obligatory, though no report about it is sahih, except that its meaning is that a person must seek the knowledge he needs concerning his wudu, his prayer, and his zakat..."Ibn Abdul-Barr said, "Ishaq means, and Allah knows best, that the hadith about the obligation of seeking knowledge has chains that scholars have criticized, but its meaning is sound according to them." Jami Bayan Ilm (1/53).Bayhaqi said in Madkhal (325), "Its wording is well known, but its chains are daif. I do not know of a chain by which such a hadith could be established."Sakhawi said in Maqasid Hasana (660), "Abu Ali Nisaburi, the Hafiz, said, 'No sahih chain has been established for it from the Prophet ﷺ.' Ibn Salah cited it as an example of a well-known statement that is not sahih, and in this he followed Hakim. But Iraqi said, 'Some of the imams have graded some of its paths as sahih, as I have explained in my checking of Ihya.' And Mizzi said, 'Its paths together reach the level of hasan.'" End, in abridged form.Since none of these paths met the criteria of the Jami Kamil, I did not include it therein.As for its meaning, Hasan bin Rabi Khashshab said, "I asked Ibn Mubarak, I said, 'Seeking knowledge is an obligation upon every Muslim,' what does this mean?' He said, 'It is not what they seek. Rather, seeking knowledge is an obligation, meaning that a man encounters something concerning a matter of his religion and asks about it until he learns it.'" Madkhal (329).