Shaykh ‘Abd al-‘Azeez ibn Baaz (may Allaah have mercy on him) said: “If a person comes late to the mosque and the people have already prayed, and he finds someone who joined the prayer late still praying, it is prescribed for him to pray with him and to stand to the right of the one who had joined the prayer late, seeking the reward of praying in jamaa’ah (congregation). The one who had joined the prayer late should then intend to lead the other man. There is nothing wrong with that according to the more correct of the two scholarly opinions. Similarly, if he finds a man praying alone after the imaam has said the salaam, it is prescribed for him to pray with him and to stand on his right, seeking the reward of praying in jamaa’ah (congregation). When the one who had joined the prayer late or the one who was praying alone says the salaam, then the one who came in last should stand up and complete his prayer, because of the general meaning of the evidence which speaks of the virtue of praying in congregation, and because it was proven that when the Prophet (peace and blessings of Allaah be upon him) saw a man who had entered the mosque after the prayer was over, he said, “If anyone wants to do this man a favour, let him pray with him.” (Narrated by Abu Dawood, 574..