If the Imaam made a mistake and added an extra Rakat to the prayer, the latecomers should not count this extra Rakat. For example: If the Imaam forgot and added a fifth Rakat to the Dhuhr prayer, and there comes a man to the Masjid who missed the first two Rakat, but he prayed three Rakat with the Imaam knowing that the Imaam made an addition, in this case, he should not count this extra Rakat and make up for what he has missed.
Shaikh Ibn Baaz said:
❝According to the more correct of the two opinions of scholars, if the Imaam unintentionally adds an extra Rakat, then the one joining him later in Salaah does not count it since it was done unintentionally by the Imaam. The person must complete the Salaah by performing (whatever he has missed without counting this extra Rakat) and then offer Sujood-ul-Sahw (Prostration of Forgetfulness) if he has not done so with the Imaam. If so, this suffices him. May Allaah grant us success.❞
Find out how to make Salah