This was revealed while the Messenger of Allah ﷺ was still in hiding at Makkah. When he prayed with his companions he would raise his voice in reciting the Quran, and when the idolaters heard him they would revile the Quran, the One who sent it down, and the one who brought it. So Allah said to His Prophet ﷺ, "And do not be loud in your prayer" meaning, in your recitation, so that the idolaters hear it and revile the Quran, "nor be too quiet in it" from your companions, so that they cannot hear you, "but seek a way between that" [Isra 17:110].
في قوله تعالى: {ولا تجهر بصلاتك ولا تخافت بها}
نزلت ورسول الله ﷺ مختف بمكة كان إذا صلى بأصحابه رفع صوته بالقرآن فإذا سمعه المشركون سبوا القرآن ومن أنزله ومن جاء به فقال الله تعالى لنبيه ﷺ: {ولا تجهر بصلاتك} أي: بقراءتك فيسمع المشركون فيسبوا القرآن {ولا تخافت بها} عن أصحابك فلا تسمعهم {وابتغ بين ذلك سبيلا}.
Bukhari related it in the tafsir (4722), and Muslim in the prayer (446), both of them through Hushaym, who said, Abu Bishr told us, from Saeed bin Jubayr, from Ibn Abbas, and he mentioned it. The wording given is that of Bukhari, and the wording of Muslim is similar.