Why did Shimon and Levi kill the people of Shechem before they killed Shechem and Chamor, the perpetrators of the sin?
Seforno: Because the latter were hiding, and they were only able to kill them once they found them.
Or ha'Chayim: Because the people were protecting their king and would not allow them access to him, thereby rendering them accessories to the crime. 1
This also explains why they killed the people, who were otherwise innocent. See Or ha'Chayim for an additional reason for that.