Ramban (see the translation in Judaica press Shoftim pages 367-371) has a big discussion about the matter. One should note that he explicitly states that this is not the same as the case of S'dom since it was only a small group of people who just wanted to "enjoy" immorality. Ramban states that some of them were "baalei Givah".
The rest of Bnai Yisrael (Mallbim says both the Sanhedrin of the other tribes and the Eidah 20:1) immediately arose and wanted to put them to death even though the miscreants were not technically liable for the death penalty (because of no witnesses or warning and that they released the concubine [not an aishes ish] who was able to return to the house and died of exposure). Daas Sofrim states that it was because of the lack of a king that they relied on the testimony of the Levite himself.
This judgement has its origin in the priciple which our Rabbis have
stated(Yevamos 90b): "The Court may administer lashes and the death
penalty which are not authorized by the Tora. However, they may not do
this [with the intent of instituting a law which] transgresses the
Torah but only for the purpose of erecting a fence around the Tora.
The tribe of Benjamin, however, did not consent to this as they were
not guilty of the death penalty for violating the concubine. Perhaps
the Benjamites were also provoked by the fact that the tribes did not
communicate with them first and reached a consensus without asking for
their opinion.
In my opinion, this [failure to consult Benjamin] caused Israel's
punishment which resulted in their being routed at first since the war
was done not in accordance with the law. The obligation of making
the "fence" lay upon the tribe of Benjaminand not upon them, as it is
the tribe itself that is obliged to judge its constituents.
Thus we see that both groups were deserving of punishment. Benjamin forgot to punish the sinners in its insistence on maintaining its prerogative (though they might have done so later had the war not broken out). The other tribes sinned but not asking Hashem first if they should go to war but only "Who shall go up for us first to battle against the children of Benjamin?
Benjamin compounded the error by not just driving the tribes away but "seeking to destroy them by a perpetual hatred" (Yechezkel25:15). Bnei Yisrael, while they asked for permission to continue to fight, still hads not completely atoned and did not ask about victory because they still relied on natural means. When they finally atoned for this, they still sinned by letting their anger continue to have control of them and killing all the men women and children of Benjamin aside from the men who escaped from the battle.
Ramban says that it could be that the total killed on both sides (with the men women, and children additional) the total killed was equal (40,000) on each side, making the punishment on each side equal.
Ramban then goes into why this occurred.
And how significant are the words of our Rabbis (Sanhedrin 103b) who
said that the anger of Hashem at that time was due to the idol of
Micah (Shoftim chapter 17)! Said the Holy One, blessed be He,
'Concerning My honor, which was violated by those guilty of death and
thosed who raised their hand against the priciple of religion, namely,
the unity of Hashem, you did not protest; but for the honor of a
mortal you did protest, to an extent which exceeded the limits of
justice'.
Therefore He confounded the counsel of the two groups and made their
hearts stubborn, and they remembered not the brotherly covenant.
(Amos 1:9). But after the affair they had regrets, just as it is said
(Shoftim 21:2-3) ... For now they realized their mistake and
punishment.
We have thus incidently explained a concealed matter which is not
clear [with a cursory reading of the text], and we have mentioned the
cause thereof.