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 solely to learn or teach goodness is like a warrior in the path of Allah, and whoever comes for any other purpose is like someone who looks at something that belongs to someone else.
Hadith Referenceمسند احمد / مسند المكثرين من الصحابة / 9419
Hadith Gradingحکم دارالسلام:حدیث ضعیف ، اختلف في إسنادہ علی المقبري ، وحمید مختلف فیه