Shaykh al-Islām was asked:
A man prayed two rak‘ahs of the obligatory Dhuhr prayer, then gave the closing salutation. He did not remember this until he was reciting the testimony of faith after two rak‘ahs of the obligatory Asr prayer. What should he do?
He replied:
If he is praying behind an imam, he should complete Asr and then make up Dhuhr. Scholars hold two opinions on whether he must repeat Asr. This question rests on the premise that his Dhuhr prayer became invalid because of the long interval and his having begun another prayer. He is therefore in the same position as someone who has missed Dhuhr. If someone has missed Dhuhr and the congregational Asr prayer is being held, he should pray Asr and then pray Dhuhr. Must he then repeat Asr? The Companions and scholars hold two opinions on this.
The first is that he must repeat it. This is the position of Abū Hanīfah and Mālik, and the well-known position in Ahmad’s school.
The second is that he need not repeat it. This is the opinion of Ibn ‘Abbās, the position of al-Shāfi‘ī, and the view preferred by my grandfather.
If he remembers the missed prayer during the current prayer, the ruling is the same as if he had remembered it before beginning. But if he does not remember the missed prayer until he has completed the current one, the current prayer suffices according to the majority of scholars, including Abū Hanīfah, al-Shāfi‘ī and Ahmad. As for Mālik, I believe it is most likely that his school holds it to be invalid. And Allah knows best.