سُبْحَانَ ٱللَّٰهِ
Holy Qur'an
Al-Qur'an
Kids Qur'an
This is a reference to the conditions prevailing at Medina at the time of the Prophet's hijrah. The two Arab tribes of Medina - Al-Aws and Khazraj - were in pre-Islamic times permanently at war with one another; and out of the three Jewish tribes living there - the Banu Qaynuqa', Banu 'n-Nadir and Banu Qurayzah - the first-named two were allied with Khazraj, while the third was allied with Al-Aws. Thus, in the course of their warfare, Jew would kill Jew in alliance with pagans ("aiding one another in sin and hatred"): a twofold crime from the viewpoint of Mosaic Law. Nevertheless, they would subsequently ransom their mutual captives in obedience to that very same Law - and it is this glaring inconsistency to which the Qur'an alludes in the next sentence.
The indigenous people of Medina were divided into two warring groups: Al-Aws and Al-Khazraj. Some Jewish tribes were allied with the former and others with the latter, which meant that in times of war each of these Jewish tribes had to fight along with their allies against their enemies, including other Jews. When the Prophet (ﷺ) migrated to Medina, he brought about a lasting peace in the city.
I understand "ransom them" here to mean "take ransom for them" though most of the Commentators take it to mean "give ransom for them". Mustafa had made a Pact which, if it had been faithfully observed by all parties, would have brought a reign of law and order for Medina. But some of the treacherous Jews never intended to observe its terms. They fought and slew each other and not only banished those who were obnoxious to them but intrigued with their enemies. If by chance they came back into their hands as captives, they demanded ransom for them to return to their homes although they had no right to banish them at all. If we understand by "ransom them" pay "ransom for them to release them from the hands of their enemies," it would mean that they did this pious act for show, although they were themselves the authors of their unlawful banishment. I think the former makes better sense.