Abu Hurairah reported,

I heard the Messenger of Allah ﷺ say, "Whoever comes to this mosque of mine for no purpose other than to learn something good or to teach it is like a Mujahid in the path of Allah. Whoever comes for any other reason is like a man who merely gazes at another's possessions."

Ibn Majah 227

Hasan

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

عن أبي هريرة قال

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

ابن ماجه 227حسن
Contents
Reference
Commentary
Ayat
Collection
Sunan Ibn Majah
Book
Sunnah
Chapter
Virtue of scholars and the encouragement to seek knowledge
Numbering
Darussalam 227
Ibn Majah 227