Somerset could've easily stopped Mills from killing Doe
Remember, Mills never saw inside the box. So Somerset could've said something like this: "I swear to god that's not Tracy. She's white, the woman in that box is black. Doe must've seen her near your apartment, and thought she was your wife."
Of course that's not very plausible, but it would've made Mills very confused, he would've been unable to do anything other than stand there wondering what's going on. This would've given Somerset enough time to grab Doe, drag him to the car, and drive away.