It is allowed for the imam or one who is offering salah by himself to pray between two walls or enclosures. Al-Bukhari and Muslim record from Ibn ‘Umar that when the Prophet entered the Ka’bah, he prayed between two walls.
Sa’id ibn Jubair, Ibrahim at-Taimi, and Suwaid ibn Ghuflah led the people in salah while they were between two columns. It is disliked for the followers to pray between them if they have enough room because it cuts the row, but they may do so if they are constrained to it.
Anas says: “We were prohibited to offer salah between walls and we would keep others from it.” This is related by al-Hakim who says it is sahih.
Mu’awiyyah ibn Qurrah relates that his father said: “We were prohibited to make rows between walls during the time of the Prophet and we kept others from it.” This is related by Ibn Majah but one of its narrator is majhul (unknown as a trustworthy person). Sa’id ibn Mansur records in his Sunan that Ibn Mas’ud, Ibn ‘Abbas, and Huzhaifah prohibited it. Ibn Sayyid an-Nass said: “There is no known difference among the companions [on this point].”