Judges 20:42

Therefore they turned their backs before the men of Israel unto the way of the wilderness; but the battle overtook them; and them which came out of the cities they destroyed in the midst of them.

The events in Judges 17-21 occurred early in the history of the judges, even though the book's main story ends with chapter 16.
The last chapters give a history of the low state and low condition into which Israel had fallen before the call of Samuel the prophet, which stands in mighty contrast to the miracles and teaching of Jesus recorded in Luke, yet both together speak of the goodness and mercy of God.
The verse belongs to the account of the crime at Gibeah and the people's backsliding, in which the tribe of Benjamin identified itself with the offenders and the conflict ended in Benjamin's defeat.
It belongs to the account of the battle that followed the murder of the Levite's concubine, a conflict that nearly exterminated the tribe of Benjamin.

The victory described came after Israel had twice been repulsed by Benjamin.
The fleeing Benjaminites turned their backs toward the way of the wilderness, but the battle overtook them.
Those who came out of the cities were caught in the midst of the fleeing forces and destroyed.
That is, the Israelites coming from the cities attacked and destroyed the Benjaminites in the midst of the fleeing forces.

The account is one of disgrace and punishment following backsliding, showing that there is no excuse for sin.
An apparent defeat need not be final, for God may allow His people to be humbled and distressed before giving them victory when they turn to Him.
Benjamin was a small, nearly extinct tribe, so choosing Saul from it helped remove grounds for jealousy among Israel's other tribes.