Abu Huraira reported: The Messenger of Allah, peace and blessings be upon him, said, “Whoever enters our mosque to teach goodness, or to learn it himself, is like one waging jihad in the way of Allah. Whoever enters it for another reason, he is an observer of what does not belong to him.”
Source: Ṣaḥīḥ Ibn Ḥibbān 87
Grade: Hasan (fair) according to Al-Arna’ut
عَنْ أَبِي هُرَيْرَةَ عَنْ رَسُولِ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ قَالَ مَنْ دَخَلَ مَسْجِدَنَا هَذَا لِيَتَعَلَّمَ خَيْرًا أَوْ يُعَلِّمَهُ كَانَ كَالْمُجَاهِدِ فِي سَبِيلِ اللَّهِ وَمَنْ دَخَلَهُ لِغَيْرِ ذَلِكَ كَانَ كَالنَّاظِرِ إِلَى مَا لَيْسَ لَهُ
87 صحيح ابن حبان كتاب العلم
1/287 المحدث شعيب الأرناؤوط خلاصة حكم المحدث إسناده حسن في تخريج صحيح ابن حبان