Should the traveller pray with the second congregation, if he missed the first one, or should he pray on his own, shortening the prayer?
Question

What is the ruling if I enter the mosque when I am travelling, and I find a group of people praying other than the congregational prayer of the mosque for which the adhan and iqamah were given? Do I have to pray with them, and offer the prayer in full when they do so? Or should I pray on my own and shorten my prayer, on the basis that this is not the original congregational prayer? Is it valid for there to be two congregations or groups praying in one mosque at the same time?
Praise be to Allah.Firstly:
Prayer in congregation is not waived for the traveller, so if he hears the call to prayer, he must answer it, unless he has an excuse. This has been explained previously in the answer to question no. 40299 .
Secondly:
If someone misses the first congregational prayer because of an excuse, then he enters the mosque and finds some people praying, then in his case it is prescribed for him to join them in the prayer.
Shaykh Ibn ‘Uthaymin (may Allah have mercy on him) said:
If group of people missed the congregational prayer by accident, not deliberately, it is recommended for them to offer the prayer in congregation and not pray individually."(Nur ‘ala al-Darb 183/11).
Shaykh Ibn Baz (may Allah have mercy on him) said:
The second congregation is prescribed, and it may be obligatory, because of the general meaning of the evidence, if a person missed praying with the first congregation. So if someone comes to the mosque and the people have already prayed, and he is able to pray with another group, then it is prescribed for him to pray in congregation with them and not pray on his own. It may be said that this is obligatory, because of the general meaning of the evidence."(Majmu‘ Fatawa Ibn Baz  12/165-166).
Based on that, what is prescribed for the traveller, if he enters the mosque and finds a group of people praying together, is to pray with them. And he should offer the prayer in full, if the one who leads the prayer is a resident and offers the prayer in full.
Thirdly:
It is not permissible for there to be two congregations praying in the mosque at the same time, if one of them is the regular congregation of the mosque, or if the mosque is small, such that the two groups would disturb one another.
But if the traveller enters the mosque and finds a group of people praying that is not the regular congregation of the mosque, then he may join them, which is better, so as to increase the size of the congregation and not divide it. Or he may lead another group in prayer, if the mosque is large enough so that they will not disturb one another.
For more information, please see the answer to question no. 94877 .
And Allah knows best.