It is narrated from Hazrat Abu Huraira (may Allah be pleased with him) that the Prophet (peace and blessings be upon him) said: Whoever enters our mosque to learn or teach goodness is like a Mujahid in the way of Allah, and whoever comes for any other purpose is like a person who looks at something which he has no right to look at.
Hadith Referenceمسند احمد / مسند المكثرين من الصحابة / 8603
Hadith Gradingحکم دارالسلام:حدیث ضعیف ، و اختلف علی سعید المقبري في إسنادہ ، و حمید مختلف فیه