Al-Bukhari recorded that Muhammad bin Abdur Rahman, Abu Al-Aswad said, “The people of Madina were forced to prepare an army to fight against the people of Syria during the Khilafah of Abdullah bin Az-Zubayir at Makkah, and I was enlisted in it. Then I met Ikrimah, the freed slave of ibn Abbas radhiAllahu anhu and informed him about it, and he forbade me strongly from doing so (i.e. to enlist in that army), and then he said to me, ‘Ibn Abbas told me that some Muslims used to go out with the idolators increasing the size of their army against the Messenger of Allah. Then, an arrow would hit one of them and kill him, or he would be struck on his neck (with a sword) and killed, and Allah subhanahu wa ta’ala sent down the ayah,
إِنَّ الَّذِينَ تَوَفَّـهُمُ الْمَلَـئِكَةُ ظَـلِمِى أَنفُسِهِمْ
“Indeed, those whom the Angels take (in death) while they were wronging themselves…”
Ad-Dahhak stated that this ayah was revealed about some hypocrites who did not join the Messenger of Allah sallAllahu aalyhi wa sallam but remained in Makkah and went out with the idolators for the battle of Badr. They were killed among those who were killed. Thus, this honorable ayah was revealed about those who reside among the idolators, while able to perform hijrah and unable to practice the faith. Such people will be committing injustice against themselves and falling into a prohibition according to the consensus and also according to this ayah, by refraining from hijrah.