At the end of Parshat Balak we get the following sequence:
- The people, en masse it appears, go after Ba'al Peor.
- God tells Moshe to execute all the leaders in response.
- Moshe tells the judges to kill everyone in their jurisdictions who sinned with Ba'al Peor.
- Zimri, a leader within Shimon, defies all this right there in front of the Ohel Moed and Pinchas takes action.
This leaves me wondering how Zimri survived as long as he did. According to this answer, Rashi citing Yerushalmi says the judges carried out those executions, though the Ramban says they didn't. If they did, how did they miss Zimri? Or did Zimri sin only after all these events -- he'd been faithful up until then but then something happened to him? Or is Zimri's survival until then evidence that the executions didn't happen?