If a traveling person comes upon a congregation praying, and he does not know if: (1) the imam (prayer leader) is a traveler, meaning that he should join the prayer with the intention of qasr (shortening prayer), or (2) if he is resident, and thus should pray the complete prayer, what should he do?
The answer that is apparent is: he acts based on what is clear to him from the signs of travel on the imam from clothes or travel gear. If it appears to him that the imam is resident, then he should pray the complete prayer.
The evidence: what Imam Ahmad authenticated and narrated that Ibn Abbas was asked: "What is reason that the traveler prays two rakaat (iterations of prayer) if he is alone and four rakaat if he is led in [a full] prayer by a resident? So he said, that is the sunna (tradition of the Prophet ), and in another narration "That is the sunna of Abi Al-Qasim."
Take the case of one who assumes that the imam is a traveler, and thus prays with him two rakaat with intention of qasr. Then, after salaam (completion of prayer) with the imam, it becomes clear to him [from speaking with others after the prayer, for example] that the imam is actually a resident and that the two rakaat that he had prayed were the imam’s third and fourth. In such an instance, he should stand up and make two rakaat to complete the prayer, he makes sujood sahw (an extra two prostrations). Whatever speaking was done or questions asked to investigate do not harm his prayer.1
From the book What Should You Do in the Following Situations... ?
1 Al-Majmooa lil-Nawawi 4/356