Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:4:75

And what is ˹the matter˺ with you that you fight not in the cause of Allah and ˹for˺ the oppressed among men, women, and children who say, "Our Lord, take us out of this city of oppressive people and appoint for us from Yourself a protector and appoint for us from Yourself a helper?"  

What is wrong with you, that you do not fight: this is an interrogative of rebuke, in other words, there is nothing to prevent you from fighting, in the way of God, and for, the deliverance of, the oppressed men, women, and children, whom the disbelievers persecuted and prevented from emigrating. Ibn ‘Abbās, may God be pleased with him and his father, said, ‘My mother and I were among them’; who say, supplicating, ‘O, our Lord, bring us forth from this town, Mecca, whose people are evildoers, through unbelief, and appoint for us a protector from You, to take charge of our affair, and appoint for us from You a helper’, to defend us against them. God responded to their supplication and facilitated escape for some of them, while others remained behind until Mecca was conquered — in charge of them the Prophet (s) placed ‘Attāb b. Asīd, who proceeded to seek justice for the wronged from those that had wronged them.
القرآن:٤:٧٥

وَمَا لَكُمْ لَا تُقَاتِلُونَ فِي سَبِيلِ اللَّهِ وَالْمُسْتَضْعَفِينَ مِنَ الرِّجَالِ وَالنِّسَاءِ وَالْوِلْدَانِ الَّذِينَ يَقُولُونَ رَبَّنَا أَخْرِجْنَا مِنْ هَٰذِهِ الْقَرْيَةِ الظَّالِمِ أَهْلُهَا وَاجْعَلْ لَنَا مِنْ لَدُنْكَ وَلِيًّا وَاجْعَلْ لَنَا مِنْ لَدُنْكَ نَصِيرًا  

{وما لكم لا تقاتلون} إستفهام توبيخ، أي لا مانع لكم من القتال {في سبيل الله و} في تخليص {المستضعفين من الرجال والنساء والولدان} الذين حبسهم الكفار عن الهجرة وآذوهم، قال ابن عباس ؓ: كنت أنا وأمي منهم {الذين يقولون} داعين يا {ربنا أخرجنا من هذه القرية} مكة {الظالم أهلُها} بالكفر {واجعل لنا من لدنك} من عندك {وليّاً} يتولى أمورنا {واجعل لنا من لدنك نصيرا} يمنعنا منهم وقد استجاب الله دعاءهم فيَسَّر لبعضهم الخروج وبقي بعضهم إلى أن فتحت مكة ووَلَّى ﷺ عتاب بن أسيد فأنصف مظلومهم من ظالمهم.