Praise be to Allah.
The reward for having prayed qiyaam all night will not be recorded for him unless he offered all the prayers with all of them. If he leaves after the first or second imam finishes, and he does not complete the prayer with the third imam, then nothing will be recorded for him except what he prayed only.
The words of the Prophet (peace and blessings of Allaah be upon him), “Whoever prays with the imam until he finishes, Allaah will record for him as if he spent the whole night in prayer” were narrated by al-Tirmidhi (806) and classed as saheeh by al-Albaani in Saheeh al-Tirmidhi. What is meant is encouragement not to leave before the prayers are completed, even if there is more than one imam.
Shaykh Ibn ‘Uthaymeen (may Allaah have mercy on him) was asked: Some people in al-Masjid al-Haraam pray qiyaam and not Taraweeh on the grounds that they are following the Sunnah and not doing more than eleven rak’ahs. What is your opinion?
What I think is that a person should do both Taraweeh and qiyaam, so he should pray with the first imam until he finishes, and pray with the second imam until he finishes, because having a number of imams in one place means that it is as if the two imams are one imam, as if the second imam is representing the first imam in the later prayers. What I think in this case is that one should stay and pray with both the first and second imams so that he will be included in the words of the Prophet (peace and blessings of Allaah be upon him): “Whoever stands (and prays) with the imam until he finishes, Allaah will record for him (a reward) as if he spent the whole night in prayer.” End quote.
Majmoo’ Fataawa Ibn ‘Uthaymeen (14/190).
He also said:
If there are two imams in one mosque, should they be regarded as separate or is one the deputy of the other?
It seems that the second option is correct, that one of them is the deputy of the other and completes (the prayer) on his behalf. Based on this, if two imams pray in the mosque, then these two imams are to be regarded as if there was one imam, so a person should stay until the second imam finishes, because we know that the second one is completing the prayer of the first one. End quote.
Majma’ Fataawa Ibn ‘Uthaymeen (14/207).
And Allaah knows best.