Greeting Muslims inside a mosque
What is the ruling of greeting those already sitting inside a mosque? Should one greet them before or after performing the two rak'as for entering the mosque?
Greeting those sitting inside a mosque
A Muslim must greet others in the mosque; this has nothing to do with performing the prayer for entering the mosque. If upon entering the mosque he finds others already present, he should greet them before performing the prayer for entering it and not postpone greeting them until he finishes the prayer. Otherwise, he is to pray and not be too particular about greeting those who are sitting at a distance from him inside the mosque.
Textual evidence from the sunna
The Messenger of Allah (peace and blessings be upon him and his family) said: "A Muslim has six rights over another Muslim." "What are they, O Messenger of Allah?" he was asked. He replied, "Greeting him when you meet him, accepting his invitation when he invites you, counseling him when he asks for your advice, invoking Allah's mercy upon him [tashmeet] when he sneezes, visiting him when he is ill, and following his funeral procession when he dies" [Reported by Bukhari and Muslim. The hadith is in Muslim's phrasing].
Allah Almighty knows best.