In the process of saving their sister Dina from and taking vengeance against Shchem, Shimon and Levi kill the entire population of the city. Since the halahca forbids the murder of gentiles, various commentators try to understand under what halacha were Shimon and Levi permitted to harm the rest of the city which was apparently not guilty of kidnapping. Here is an overview of some of the answers.
The Rambam writes (הלכות מלכים ומלחמות ט:יד):
ומפני זה נתחייבו בל בעלי שכם הריגה שהרי שכם גזל והם ראו וידעו ולא דנוהו
And this is why the citizens of Shchem deserved to be killed. Since Shchem was guilty of kidnapping and they saw and knew [that he kidnapped] and did not judge him.
Rambam claims that the whole city was guilty of abrogating the Noachide law of dinim or setting up courts of justice. Since according to most opinions, the punishment for the abrogation of any of the Noachide laws is death, the whole city was deserving of death for this infraction.
The Ramban disagrees, he quotes the opinion of the Rambam and challenges the Rambam understanding of the nature of the Noachide law of Dinim. He then goes on to challenge the Rambam's approach to the story of Schem (בראשית לד וישלח):
ומה יבקש בהן הרב חיוב, וכי אנשי שכם וכל שבעה עממין לא עובדי עבודה זרה ומגלה עריות ועושים כל תועבות השם היו
Why does the Rav [Rambam] look for [a specific sin] to obligate them [for death]. Were not the people of Shchem and all the seven nations Idol worshipers and [guilty of] sexual indiscretions and committed all that is an abomination to Hashem.
The Ramban basically disagrees that one can be put to death for not imposing justice (especially when the people were probably powerless to execute judgment against their king). He instead proposes that this city was an evil society and every individual was guilty of one form or another of evil behavior.
The Ohr HaChaim gives two explanations of his own (וישלח לד כה). The first is that Shimon and Levi really only intended to kill Shchem but they expected the rest of the city to come and defend their king. Therefore, the rest of the city had the status of Rodfim or people who are pursuing you in order to kill. Because of their status as Rodfim, Shimon and Levi were permitted to kill them. The Ohr HaChaim's second explanation is that the rest of the city were accomplices to the kidnapping. By enabling Shchem to perpetuate his crime, they were also guilty and deserved punishment.
The Maharal in Gur Aryeh gives yet another explanation. He says that Shchem's act is considered an act of war against the Jewish people. Shimon and Levi were on a mission to extract vengeance for Hashem and all the dinim of their mission were only constrained by the halachas of war. Since in war, it is not individual against individual but rather nation against nation, they had no liability for the civilian casualties of Shchem even if individually, those people they killed were not guilty of any specific crime.
If anyone has any more explanations, I would love to hear them.