The World Federation One Stop Fiqh

Ruling 1351

If a traveller who must perform tamām prayers on account of not knowing the ruling starts performing prayers with the intention of performing a two rakʿah prayer, and he becomes aware of the ruling during prayers, he must complete the prayer as a four rakʿah prayer. And the recommended precaution is that after completing the prayer, he should perform that prayer again as a four rakʿah prayer.