Repeating a prescribed prayer to attain the reward of a group prayer
The inquirer wishes to know the ruling for someone who performs the prescribed Maghrib (Sunset) prayer individually, and upon finishing finds a group of people performing the same prayer in congregation and joins them. Is he to pray three rak'as (cycles of prayer) or is he to add a fourth?
Group prayer is superior to individual prayer since its reward is 27 times greater. The Prophet said, "Group prayer is 27 times greater [in reward] than an individual prayer" [recorded in Malik's Muwatta`]. In another narration it is said to be 25 times greater.
The Prophet exhorted those who had already completed a prescribed prayer to join any congregation they come across performing the same prayer. Abu Dharr (may Allah be pleased with him) related that the Prophet said, "Offer prayers at their prescribed times; if you thereafter come upon a congregation offering the same prayer, pray with them and it will be counted as a nafilah (voluntary prayer) for you" [recorded by Abu Dawud].
The pronoun "it" may either refer to the prayer offered alone or to the one performed in a group — scholars have offered both opinions. The purport of the hadith is that one will count as the prescribed prayer while the other will count as a nafilah since a person cannot technically offer the same prescribed prayer twice on the same day. Therefore, one will fulfill the obligation of the prescribed prayer while the other will earn one a reward with the grace and mercy of Allah, though it is not considered the prescribed prayer for the reason mentioned above.
There is no objection to the nafilah being two, three or four rak'as. Mu'adh (may Allah be pleased with him) used to offer the 'Isha (Night) prayer with the Prophet and later lead the people in the same prayer which was counted as obligatory for them and voluntary for him. Abu Dawud's hadith is general — it does not exclude the three rak'a prayer from the rest. Based on this it does not make sense to exclude it or add an additional one.
Allah the Almighty knows best