They pray Taraweeh and tahajjud in their mosque; how can they finish with the imam?
Question

In one of the fatwas on your website, you said that whoever prays Taraweeh with the imam until he finishes, it will be recorded for him as if he spent the entire night in prayer. Here in our mosque, in the last ten nights of Ramadan, they pray Taraweeh with twenty rak‘ahs, along with three rak‘ahs of Witr, after ‘Isha’. Then they pray tahajjud a few hours before before sahoor, sometimes with eight rak‘ahs, along with three rak‘ahs of Witr. How should we pray in this situation, so that we can guarantee that we will attain the reward of spending the entire night in prayer?
Praise be to Allah.It was narrated from Abu Dharr (may Allah be pleased with him) that the Messenger (blessings and peace of Allah be upon him) said concerning Taraweeh prayer: Whoever prays qiyaam with the imam until he finishes, it will be recorded for him as if he spent an entire night in prayer.” Narrated by at-Tirmidhi (806); he said: This is a saheeh hasan hadith. Also narrated by Abu Dawood (1375). Classed as saheeh by al-Albaani in Irwa’ al-Ghaleel (2/193). 
This virtue is for the one who prays Taraweeh with the imam and finishes with him. 
The end of Taraweeh prayer and its completion at which the imam finishes has been defined by Islamic teaching as being Witr prayer, as is narrated in saheeh reports from the instructions and actions of the Prophet (blessings and peace of Allah be upon him). 
It was narrated from ‘Abdullah ibn ‘Umar (may Allah be pleased with him) that the Prophet (blessings and peace of Allah be upon him) said: “Make the last of your prayers at night Witr.” Narrated by al-Bukhaari (998) and Muslim (751). 
Whether the prayer is directly after ‘Isha’ or at the end of the night, in order to attain the virtue of praying during the last third of the night, all of that is prescribed. 
It was narrated that Jaabir (may Allah be pleased with him) said: The Messenger of Allah (blessings and peace of Allah be upon him) said: “Whoever fears that he will not get up at the end of the night, let him pray Witr at the beginning. Whoever is sure that he will get up at the end of the night, let him pray Witr at the end, for prayer at the end of the night is witnessed, and that is better.” Narrated by Muslim (755).
Based on that, whoever prays twenty rak‘ahs with the first congregation after ‘Isha’ prayer, and prays Witr with the imam of that congregation, has completed Taraweeh prayer by praying Witr with the imam, and has fulfilled the condition of attaining the reward of spending the entire night in prayer by finishing with the imam, and he does not have to pray with another imam at the end of the night, because the first prayer is complete. 
Whoever wants to pray both prayers, seeking more reward, is doing something good, but he should not pray Witr twice, because the Prophet (blessings and peace of Allah be upon him) forbade doing that. 
It was narrated from Qays ibn Talq ibn ‘Ali, from his father, who said: I heard the Messenger of Allah (blessings and peace of Allah be upon him) say: “There should not be two Witrs in one night.” Narrated by at-Tirmidhi (470); classed as hasan by al-Haafiz Ibn Hajar in Fath al-Baari (2/481). Classed as saheeh by al-Albaani in Saheeh Sunan at-Tirmidhi (470). 
In that case, he has two options, each of which was the view of a group of scholars: 
The first option: when he prays with the first imam and prays Witr with him, he may add a rak‘ah so that it will become even-numbered, then at the end of the night if he wants, he may join the other imam in his prayer and join him in Witr too. 
The second option: he may pray the first Witr as such, then when the second imam prays Witr  at the end of the night, he may either leave and not pray with him, or he may pray with him and add another rak‘ah, intending it to be qiyaam al-layl. 
At-Tirmidhi (may Allah have mercy on him) said: 
The scholars differed concerning the one who prays Witr at the beginning of the night then prays qiyaam at the end of the night…
Some of the scholars among the companions of the Prophet (blessings and peace of Allah be upon him) and others said: If he prays Witr at the beginning of the night, then sleeps, then gets up at the end of the night, he may offer whatever prayers he likes, but he should leave his Witr as it was. This is the view of Sufyaan ath-Thawri, Maalik ibn Anas, Ibn al-Mubaarak, ash-Shaafa‘i, the scholars of Kufah, and Ahmad. 
This is more correct, because it was narrated via more than one isnaad that the Prophet (blessings and peace of Allah be upon him) prayed after Witr. 
End quote from Sunan at-Tirmidhi (2/334) 
For more information, please see fatwa no. 155649 
And Allah knows best.