A traveller caught up with the imam at the end of the prayer and does not know if the imam was offering the prayer in full or shortening it. Should he offer the prayer in full or shorten it?
Question

I was travelling and I joined a congregation in prayer when they were reciting the final tashahhud, but I did not know whether they were offering the prayer in full or shortening it, so I offered the prayer in shortened form. There was another congregation who were praying Maghrib, so I waited until the final rak`ah of Maghrib remained, then I joined them with the intention of praying `Isha, and offered that prayer in shortened form too. Is what I did correct?
Praise be to Allah.Firstly:
If a traveller is unsure whether the imam he is praying behind is a traveller or a resident, then it must of either of two scenarios:

There is something to indicate whether the imam is travelling, such as if he is praying in one of the roadside mosques, or a mosque in an airport, or the imam’s clothing and the luggage he has with him indicate that he is travelling. In that case, the traveller may shorten his prayer, based on that corroborating evidence.
If there is nothing to indicate whether the imam is a traveller, in this case the traveller should offer his prayer in full behind that imam.

It says in al-Mawsu`ah al-Fiqhiyyah, 29/187.
The Hanbalis said: If someone starts to pray behind someone who he thinks is a resident (non-traveller), or he is not sure about him, he must offer the prayer in full even if that imam shortens his prayer, based on the intention. If he thinks it most likely that he is a traveller based on evidence to that effect, then he may form the intention to shorten the prayer and follow the imam, then he must shorten the prayer if the imam shortens the prayer and offer it in full if the imam offers it in full. End quote.
Shaykh Ibn `Uthaymin (may Allah have mercy on him) was asked: What is the ruling if I go to the mosque and find the imam reciting the final tashahhud, so I join him in the prayer and say the salaam, but I do not know whether he offered a four-rak`ah prayer in full or shortened it?
He (may Allah have mercy on him) replied: In this case, he should look at what the situation appears to be, because what you mention could have been in some mosques, when a person passes by on the road and finds some people praying, or in the airport he could find some people praying, so he is not sure whether they are residents or travellers. He should look at what appears to be the case, and if what appears to be the case is that this man is a traveller, because he has his suitcase in front of him, and because he is wearing travelling clothes, then he should be regarded as a traveller, and if nothing appears clearly to be the case, then he should offer the prayer in full, because the basic principle is that the prayer is to be offered in full.
(End quote from Ibn `Uthaymin: Liqa’ al-Bab al-Maftuh)
Based on that, with regard to that prayer that you offered in shortened form, when you did not know about the situation of the person behind whom you prayed, and whether he was offering the prayer in shortened form or not, then to be on the safe side, you should repeat it now in full, with four rak`ahs, unless there was something to indicate that the imam was a traveller, in which case your prayer was valid.
Secondly:
In the answer to question no. 136938, we explained that the traveller may offer `Isha’ prayer in shortened form with two rak`ahs behind someone who is praying Maghrib, and he may also offer it in full, with four rak`ahs.
And Allah knows best.