The prayer of a traveller behind a resident, and of a resident behind a traveller
It is permissible and valid, and the evidence for it is as follows:
➊ If a traveller prays behind a resident, he will pray the full prayer, and if he prays alone, he will shorten the prayer, as Ibn Abbas (may Allah be pleased with them both) was asked: “What is the case of the traveller who prays two rak’ahs when he is alone, but prays four rak’ahs when he is following a resident imam?” He replied: تلك السنة “That is the sunnah.”
➋ It is narrated from Imran ibn Husayn (may Allah be pleased with him) that the Messenger of Allah ﷺ always prayed two rak’ahs when travelling, until he returned. Apart from Maghrib, when he ﷺ had prayed two rak’ahs, he would say:
يا أهل مكة قوموا فصلوا ركعتين أخريين فإنا قوم سفر
“O people of Makkah! Stand up and pray the other two rak’ahs; we are indeed a travelling people.”
➌ It is narrated from Umar (may Allah be pleased with him) that he ﷺ came to Makkah, led the prayer of two rak’ahs, and said:
يا أهل مكة أتموا صلاتكم فإنا قوم سفر
“O people of Makkah! Complete your prayer; we are indeed a travelling people.”