Praise be to Allah.
The fuqaha’ differed concerning the ruling on the second tasleem. The majority are of the view that it is recommended (mustahabb), but the Hanbalis are of the view that it is obligatory in the obligatory prayer, and they stated that both tasleems are an essential part of the prayer.
It says in Kashshaaf al-Qinaa‘ (1/388), discussing the essential parts of the prayer: … Thirteen: the two tasleems, because the Prophet (blessings and peace of Allah be upon him) said: “Exiting the prayer is through the tasleem.” And ‘Aa’ishah said: The Prophet (blessings and peace of Allah be upon him) would end his prayer with the tasleem. … But in the funeral prayer, the worshipper may exit from it by saying one tasleem, and in a supererogatory (naafil) prayer one tasleem is sufficient, according to the view favoured by a number of scholars, including al-Majd ‘Abd as-Salaam ibn Taymiyah.
It says in al-Mughni wa’sh-Sharh: There is no difference of opinion regarding the fact that the worshipper may exit from a supererogatory prayer with one tasleem. End quote.
According to the view that the second tasleem is recommended (mustahabb), there is nothing wrong with the one who joined the prayer late standing up before the imam says [the second tasleem]. But according to the view that it is obligatory and an essential part of the prayer, it is not permissible for him to do that, and if he does get up, he must sit back down until his imam says the tasleem, then get up to complete his prayer. If he does not sit back down, his prayer is not valid as an obligatory prayer, and it is regarded as supererogatory instead.
It says in Kashshaaf al-Qinaa‘ regarding the topic discussed above: The two tasleems are part of the prayer like all other essential parts, and the one who joined the prayer late should not stand up before the imam says them. End quote.
It says in Manaar as-Sabeel (1/119): If the one who joined the prayer late gets up before his imam says the second tasleem, and he does not sit back down, then his prayer becomes supererogatory, because he failed to sit back down, which was required in order to follow his imam, with no excuse. Thus he ceased to follow the imam and his obligatory prayer was rendered invalid. End quote.
It says in Haashiyat ar-Rawd al-Murbi‘ (2/277): Because he omitted something obligatory with no excuse that would permit him to part from his imam, his obligatory prayer was rendered invalid thereby, regardless of whether he was aware of what he was doing or did it by mistake, and whether he did it deliberately or because he was unaware of the ruling. This applies if we assume that the second tasleem is obligatory in the obligatory prayer, as noted above. For the one who does not hold that view, the prayer is not invalidated in his case, as in the case of one who is unaware of the ruling or the one who forgets and makes a mistake. As for his prayer being regarded as valid if it is a supererogatory prayer, that is based on the fact that the second tasleem is not an essential part in a supererogatory prayer, according to the madhhab. End quote.
Based on that, the one who joins the prayer late must wait until the imam says the second tasleem, then he may get up and complete his prayer, unless he believes that the second tasleem is recommended (mustahabb), in which case there is no blame on him if he gets up before the imam says it.
And Allah knows best.