If the imam makes a mistake and does the prostration of forgetfulness before the salaam, the one who joined the prayer late has to follow him, because he is connected to his imam until he says the salaam. Then when he makes up whatever he missed, he must prostrate again, because his prostration with the imam was not done at the right point in the prayer. The prostration of forgetfulness cannot be done during the prayer, rather his prostrating with the imam was only because he was following the imam.
But if the imam’s mistake occurred before the latecomer joined the prayer, then he should not repeat the prostration, because the ruling on his imam’s mistake does not apply to him, as it happened before he joined him in prayer.
But if the imam does the prostration of forgetfulness after the salaam, then the latecomer should not prostrate with him, because following the imam in this case is not possible except by saying the salaam with him, and the latecomer cannot do that, as he does not say the salaam until after he has completed his prayer.
But if the imam’s mistake came before he joined him, then he does not have to do the prostration of forgetfulness, because the ruling on his imam’s mistake does not apply to him. But if his mistake came after he joined him, then he should prostrate after he has said the salaam.
Some of the argument we have mentioned above is based on sound reports, such as the idea that the one who is praying behind the imam should prostrate following his imam, because the Prophet (peace and blessings of Allaah be upon him) said: “The imam is only appointed to be followed.” Agreed upon.
And some of it is based on sound rational thinking, as explained. See: al-Sharh al-Kabeer ‘ala al-Muqni’ and al-Majmoo’ Sharh al-Muhadhdhab. End quote.