It is narrated from Sayyiduna Sahl bin Sa'd al-Sa'idi (may Allah be pleased with him) that the Prophet (peace and blessings be upon him) said: "Whoever enters this mosque of mine to learn something good or to teach it is of the rank of one who strives (mujahid) in the path of Allah; and whoever enters it for anything else, for people's chatter, is like one who looks at something he likes that belongs to someone else."
Hadith Referenceالمعجم الكبير للطبراني / باب السين / 5890