Concerning Allah's words , "And do not be loud in your prayer, nor be too quiet in it", Ibn Abbas said that this was revealed while the Messenger of Allah ﷺ was still in hiding in Makkah. Whenever he prayed with his companions he would raise his voice. Ibn Munee said, he would recite the Quran aloud. When the polytheists heard his voice, 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 polytheists hear it and revile the Quran, "nor be too quiet in it", keeping it from your companions so that they cannot hear it, "but seek a way between that".
أخبرنا أحمد بن منيع ويعقوب بن إبراهيم الدورقي قالا حدثنا هشيم قال حدثنا أبو بشر جعفر بن أبي وحشية وهو ابن إياس عن سعيد بن جبير
في قوله عز وجل {ولا تجهر بصلاتك ولا تخافت بها} قال نزلت ورسول الله ﷺ مختف بمكة فكان إذا صلى بأصحابه رفع صوته وقال ابن منيع يجهر بالقرآن وكان المشركون إذا سمعوا صوته سبوا القرآن ومن أنزله ومن جاء به فقال الله عز وجل لنبيه ﷺ {ولا تجهر بصلاتك} أي بقراءتك فيسمع المشركون فيسبوا القرآن {ولا تخافت بها} عن أصحابك فلا يسمعوا {وابتغ بين ذلك سبيلا}
Bukhari transmitted it in the tafsir section, in the chapter titled "And do not recite your prayer aloud, nor say it too quietly," hadith 4722, from Yaqub bin Ibrahim, with this chain. Muslim also transmitted it in the prayer section, in the chapter on moderation in recitation during the audible prayer, and so on, hadith 446, through the hadith of Hushaym, with this chain. It is also found in al-Kubra, hadith 1084.