The Imaam prayed Shaf‘ and Witr‘ as three consecutive Rak‘ahs (units of prayer) like the Maghrib prayer. However, my intention was to offer them separately, in the form of two Rak‘ahs as Shaf‘ and one Rak‘ah as Witr‘. Hence, I offered Tasleem after I prayed two Rak‘ahs with the Imaam, and then I offered the Witr‘ prayer in a separate Rak‘ah. Some people, however, disapproved of me doing this. What should I have done?
All perfect praise be to Allaah, the Lord of the worlds. I testify that there is none worthy of worship except Allaah and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
If a person praying in congregation intends to offer the Shaf‘ prayer, while the Imaam intends to pray Shaf‘ and Witr‘ in a single prayer, then he has two choices:
1- To make the intention of the extra Rak‘ah (of Witr‘) in his heart and follow the Imaam in the prayer. This is stated by Al-‘Adawi, the Maaliki scholar as he said:
"It should be known that if a person joins the Imaam while knowing that he offers the three Rak‘ahs consecutively, he should comply with him, intending the first two Rak‘ahs as Shaf‘ and the third as Witr‘. If he joins the Imaam while not knowing that he offers the three Rak‘ahs consecutively and he has made the intention to pray only two Rak‘ahs as Shaf‘, then he can make the intention to pray Witr‘, without uttering it, upon seeing the Imaam offering it. This is the opinion of Al-Fakihaani ."
2- When the Imaam stands to perform the third Rak‘ah, he sits and makes the intention of leaving the prayer with the Imaam, recites Tashahhud, and offers Tasleem after these two Rak‘ahs.
In relation to this, As-Sawi, the Maaliki scholar said:
"It should be known that following an Imaam who offers the three Rak‘ahs consecutively is disliked. The prayer of someone led by such an Imaam is not invalidated if he ceased to follow him and made Tasleem after two Rak‘ahs, as complying with the opinion of Ash-hab regarding this case."
Therefore, what you have done is correct and conforms to the opinion of some scholars .
Allaah Knows best.
You can search for fatwa through many choices