This verse was revealed concerning us. Whenever the Ansar returned from performing Hajj, they would not enter through the front doors of their houses but through the back. One man from the Ansar came and entered through his front door, and he was reproached for it. Then this was revealed, "It is not righteousness that you enter the houses from their backs, but righteousness belongs to the one who is mindful of Allah. So enter the houses through their doors" [Baqarah 2:189].
نزلت هذه الآية فينا كانت الأنصار إذا حجوا فجاؤوا لم يدخلوا من قبل أبواب بيوتهم، ولكن من ظهورها، فجاء رجل من الأنصار فدخل من قبل بابه، فكأنه عير بذلك، فنزلت: {وليس البر بأن تأتوا البيوت من ظهورها ولكن البر من اتقى وأتوا البيوت من أبوبها}
Bukhari narrated it in Umrah (1803) and Muslim in tafsir (3026), both from the hadith of Shubah, from Abu Ishaq, who said, I heard Bara say, then he mentioned it.In a version from Bukhari (4512), they used to, when they entered ihram during the Jahiliyyah, come to the House from its back, so Allah revealed, then he mentioned the verse.