Divine punishment can be indiscriminate, if any of them were innocent they will be saved in the afterlife i recently read an essay which quoted some relevant passages i will copy them here as a reminder.
Surah Anfal 8:25
And fear the Fitnah (affliction and trial) which affects not in
particular (only) those of you who do wrong (but it may afflict all
the good and the bad people), and know that Allâh is Severe in
punishment.
حَدَّثَنَا عَبْدُ اللَّهِ بْنُ عُثْمَانَ، أَخْبَرَنَا عَبْدُ اللَّهِ،
أَخْبَرَنَا يُونُسُ، عَنِ الزُّهْرِيِّ، أَخْبَرَنِي حَمْزَةُ بْنُ
عَبْدِ اللَّهِ بْنِ عُمَرَ، أَنَّهُ سَمِعَ ابْنَ عُمَرَ ـ رضى الله
عنهما ـ يَقُولُ قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم " إِذَا
أَنْزَلَ اللَّهُ بِقَوْمٍ عَذَابًا، أَصَابَ الْعَذَابُ مَنْ كَانَ
فِيهِمْ، ثُمَّ بُعِثُوا عَلَى أَعْمَالِهِمْ ".
Narrated Ibn `Umar: Allah's Messenger (ﷺ) said, "If Allah sends
punishment upon a nation then it befalls upon the whole population
indiscriminately and then they will be resurrected (and judged)
according to their deeds. "
Sahih al-Bukhari 7108 https://sunnah.com/bukhari:7108
حَدَّثَنَا مُحَمَّدُ بْنُ الصَّبَّاحِ، حَدَّثَنَا إِسْمَاعِيلُ بْنُ
زَكَرِيَّاءَ، عَنْ مُحَمَّدِ بْنِ سُوقَةَ، عَنْ نَافِعِ بْنِ جُبَيْرِ
بْنِ مُطْعِمٍ، قَالَ حَدَّثَتْنِي عَائِشَةُ ـ رضى الله عنها ـ قَالَتْ
قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم " يَغْزُو جَيْشٌ
الْكَعْبَةَ، فَإِذَا كَانُوا بِبَيْدَاءَ مِنَ الأَرْضِ يُخْسَفُ
بِأَوَّلِهِمْ وَآخِرِهِمْ ". قَالَتْ قُلْتُ يَا رَسُولَ اللَّهِ
كَيْفَ يُخْسَفُ بِأَوَّلِهِمْ وَآخِرِهِمْ، وَفِيهِمْ أَسْوَاقُهُمْ
وَمَنْ لَيْسَ مِنْهُمْ. قَالَ " يُخْسَفُ بِأَوَّلِهِمْ
وَآخِرِهِمْ، ثُمَّ يُبْعَثُونَ عَلَى نِيَّاتِهِمْ ".
Narrated Aisha: Allah's Messenger (ﷺ) said, "An army will invade the Ka
ba and when the invaders reach Al-Baida', all the ground will sink
and swallow the whole army." I said, "O Allah's Messenger (ﷺ)! How
will they sink into the ground while amongst them will be their
markets (the people who worked in business and not invaders) and the
people not belonging to them?" The Prophet (ﷺ) replied, "all of those
people will sink but they will be resurrected and judged according to
their intentions."
Sahih al-Bukhari 2118 https://sunnah.com/bukhari:2118