If someone forgets a resident prayer and then remembers it while on a journey, he must perform it in full, without shortening, by unanimous consensus, because that prayer was originally fixed for him as four rakʿahs and he is not allowed to reduce their number. He is, after all, making up what he missed, and what he missed was four rakʿahs.
However, if he forgets a travel prayer and remembers it after returning home, Imām Aḥmad held that he should complete it in full as a precaution; this was also the view of al-Awzāʿī, Dāwūd, and al-Shāfiʿī in one of his two opinions. Mālik, al-Thawrī, and the scholars of opinion maintained that he should pray it as a travel prayer, for he is only making up what he failed to perform, and that was merely two rakʿahs. (1)
Allah knows best. (2)
And if he forgets it while travelling and remembers it during that same journey, or recalls it on another journey, he must make it up.
(1) Ibn Qudama, al-Mughni, 3:141–142; al-Insaf fi Ma rifat al-Rajih min al-Khilaf (published together with al-Muqni and al-Sharh al-Kabir), 5:53–54; Ibn Qasim, Hashiyat al-Rawd al-Murbi, 2:387.
(2) Shaykh Muhammad ibn Salih al-Uthaymin held that the stronger view is that whoever forgets a prayer that became due while travelling and remembers it after reaching home should still perform it shortened, because it was obligatory during travel and a travel prayer is legislatively shortened; hence completion is not required. From this, four situations arise:
1. He remembers a travel prayer while still on the journey: he shortens it.
2. He remembers a resident prayer while at home: he performs it in full.
3. He remembers a travel prayer after returning home: he shortens it (the sound view).
4. He remembers a resident prayer while travelling: he performs it in full.
See Ibn Uthaymin, al-Sharh al-Mumti, 4:517–519 and 5:542–543.