If a man enters the masjid while the imam (leader of prayer) is praying. Should he join the imam immediately in whatever position he is in and start praying, or should he wait to find out whether the imam is going to sit or stand?
The correct answer is the one to which the evidence points. And that is that he should enter with the imam no matter what part of prayer the imam is insujood (prostration), qiyaam (standing), rukuu' (bowing) or qu'ood (sitting). The evidence is the hadith of Abi Huraira (may Allah be pleased with him), in which he said, "The Messenger of Allah (peace be upon him) said, 'If you come to prayer and we are prostrating, then you should prostrate [but] dont count it, and whoever catches a rakaa, then he has caught the salaat'."1 And Muath said that [the Prophet] (peace be upon him) has said "If one of you comes to prayer and the Imam is in a certain position, then do as the Imam is doing".2 Also, the general meaning of his saying (peace be upon him), applies: "What you catch up with, pray."
From the book What Should You Do in the Following Situations... ?
1 Sunan Abu Dawood 893
and Sahih Sunan Abu Dawood 792.
2 Sunan Al-Tirmidhi 591 and Sahih Sunan Al-Tirmidhi 484..