Āyatollāh Khāmenei considers it permissible to pray congregational prayers behind the Sunnis. He says that, it is emphasized in our ḥadīths issued by Ahl al-Bayt (peace be upon them) to pray in Masjid al-Ḥarām or Masjid al-Nabī with those who are not Shiites, to participate in their prayers and, to follow them in Prayer. These are our ḥadīths; this means amiability among Muslim brothers, this is strengthens devotion between Muslim brothers.
In response to the question of whether it is possible to follow Sunnis in praying at Masjid al-Ḥarām or Masjid al-Nabī? The Fatwās of Shīʻī jurists and grand Marājʻ al-Taqlīd are presented:
Late Imām Khumaynī (may his soul rest in peace): When the congregational prayer is established in Masjid al-Ḥarām or Masjid al-Nabī, believers (Muʼminīn) should not leave there, should not violate the congregational prayer and, should pray together with other Muslims.
Āyatollāh Golpāyigānī: There is no problem in praying with the Ahl al-Sunnah when it is necessary. If not necessary, it is good to participate in their congregational Prayer, but if possible, he should repeat the prayer in full conditions.
Āyatollāh Baḥjat: If he/she does not have an important job, he/she should not leave it and it is good for him/her to participate the congregational prayer.
Āyatollāh Ṣāfī: There is no problem in praying with the Sunnis when it is necessary. If it is not necessary, participating in their congregations is good if it leads to strengthen devotion and amiability among them and repelling accusations against the Shiites. It is not necessary to repeat it, although it is in accordance with precaution (Iḥṭīyāt). It is not appropriate to leave the mosque during congregational prayer or to not participate it. Of course if necessary, there is no problem to leave it.
Āyatollāh Khuʼī and Āyatollāh Tabrīzī: This prayer is valid if he/she recites the al-Ḥamd and Sūrah slowly to himself/herself. In the Friday prayer, after leaving it, he/she should resume the noon prayer with them.
Āyatollāh Sīstānī: It is permissible to say the prayer behind them, but if the follower (Maʼmūn) can, he/she should recite it slowly to himself/herself and otherwise in his/her mind and soul. If it is a Friday prayer, he/she should recite the noon prayer after that.
Āyatollāh Shubayrī-Zanjānī: Respected pilgrims (Ḥujjāj) should refrain from doing anything that causes Shīʻas weakness. It is very appropriate for Shīʻas to participate in Sunni congregational prayers, but in the current situation, they should repeat it.
Āyatollāh Khāminiʼī also considers congregational prayer behind the Sunnis permissible and correct.
It is worth mentioning that the Supreme Leader of the Iran Revolution, Āyatollāh Khāminiʼī said in a statement during the meeting with the Hajj agents on July 3, 2019 that, one of the issues which is very important in Hajj is the issue of amiability and fraternity. In various narrations issued by the Imams (greetings be upon them), it has been stressed that you should perform daily prayers in Masjid al-Ḥarām or Masjid al-Nabī with non-Shīʼas and that you should participate in their daily prayers and perform it together. These are our narrations. This means amiability among Muslim brothers. I have heard that some people insist that people perform public prayers in caravans, in hotels and in other places. This is not the correct policy and method. They should join other people and they should perform public prayers with other Muslims in Masjid al-Ḥarām and in the orderly lines of Masjid al-Nabī. The formation of the Islamic Ummah through the great gatherings of Muslims is one of the obligations that exist in Ḥajj.