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