Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
suyuti:21250a
Request/Fix translation

  

السيوطي:٢١٢٥٠a

"مَنْ جَاءَ مَسْجِدِي هَذَا لَمْ يَأْتِه إلا لِخَيرٍ يَتَعَلَّمُهُ أَو يُعَلِّمُهُ، فَهُو بِمَنْزِلَةِ الْمُجَاهِدِ في سَبِيلِ اللهِ، وَمَنْ جَاءَ لِغَيرِ ذَلِكَ، فَهُوَ بِمَنْزِلَةِ الرَّجُل يَنْظُرُ إِلَى مَتَاعِ غَيرِهِ".  

[ش] ابن أبى شيبة [هـ] ابن ماجة [ك] الحاكم في المستدرك [هب] البيهقى في شعب الإيمان عن أَبي هريرة

See similar narrations below:

Collected by Ibn Mājah, Aḥmad
ibnmajah:227Abū Bakr b. Abū Shaybah > Ḥātim b. Ismāʿīl > Ḥumayd b. Ṣakhr > al-Maqburī > Abū Hurayrah

"I heard the Messenger of Allah say: 'Whoever comes to this mosque of mine, and only comes for a good purpose, such as to learn or to teach, his status is like that of one who fights in Jihad in the cause of Allah. Whoever comes for any other purpose, his status is that of a man who is keeping an eye on other people's property.'"  

ابن ماجة:٢٢٧حَدَّثَنَا أَبُو بَكْرِ بْنُ أَبِي شَيْبَةَ حَدَّثَنَا حَاتِمُ بْنُ إِسْمَاعِيلَ عَنْ حُمَيْدِ بْنِ صَخْرٍ عَنِ الْمَقْبُرِيِّ عَنْ أَبِي هُرَيْرَةَ قَالَ

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

ahmad:9419Qutaybah > Ḥātim b. Ismāʿīl > Ḥumayd al-Kharrāṭ > al-Maqburī > Abū Hurayrah

"I heard the Messenger of Allah say: 'Whoever comes to this mosque of mine, and only comes for a good purpose, such as to learn or to teach, his status is like that of one who fights in Jihad in the cause of Allah. Whoever comes for any other purpose, his status is that of a man who is keeping an eye on other people's property.'" (Using translation from Ibn Mājah 227)  

أحمد:٩٤١٩حَدَّثَنَا قُتَيْبَةُ قَالَ حَدَّثَنَا حَاتِمُ بْنُ إِسْمَاعِيلَ عَنْ حُمَيْدٍ الْخَرَّاطِ عَنِ الْمَقْبُرِيِّ عَنْ أَبِي هُرَيْرَةَ قَالَ

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