"And Pinchas son of Elazar son of Aaron the Priest saw...and took a spear in his hand..."
And it should not arise in your mind, God Forbid (chas v'shalom) that Zimri was an adulterer, chas v'shalom. For the Holy Blessed One would not make a whole section of the Torah out of an adulterer. Rather, there is a hidden mystery in this matter.
For there are ten levels of lust. The first level is one who dresses themselves up and deliberately goes out for sinful purposes. So this person is, drawing the Evil Urge (Yeitzer HaRa) upon himself. But after this, are another nine levels, and at each level, a person loses some of their free will, and it becomes less and less possible for them to resist the sin. Until they get to the 10th level, where someone has completely distanced themselves from the Yeitzer HaRa and guarded themselves from the sin with all their power, so much so that it would beyond their capacity to guard themselves anymore than they already have -- and then, when their desire overpowers them, and they commit the act, at that point they know for certain that their actions are the will of the Blessed God (Hashem Yisbarach).
This was the case with Yehudah and Tamar, for she was actually his soulmate. And it is the same case here, for Zimri was truly guarding himself from all evil temptation, yet the thought arose in his mind that she [Kozbi] was his soulmate, since it was not within his power to refrain from this deed.
But Pinchas said the opposite, that he [Zimri] still had the strength to refrain from this. The Talmud (in Sanhedrin 82b) hints at this: "six miracles were performed for Pinchas," as it brings there, that if Zimri got up and killed Pinchas, then he Zimri would not have been punished. Because this was truly a case of reasonable doubt, and there was surely room to make a legal case against Pinchas. Because it certainly appears to the observer that he acted out of rage....
Now Pinchas, came from the seed of Joseph, who had trials and suffering in this realm. Therefore, Zimri's deeds seemed particularly evil to Pinchas...
But the foundational depths of the matter were hidden from Pinchas, namely that she [Kozbi] had been ordained at Zimri's soulmate from the six days of Creation, as is explained in the writings of the Ari"zal. So Moshe Rabbeinu did not attempt to judge him for captial punishment. We find Pinchas acted as a foolish youth, because he did not understand the depths of the issue, and only saw through the perception of human intellect, and no more.
Nevertheless, Hashem Yisbarach loved him, and gave him approval, because according to what Pinchas' understanding, he had done a great thing out of his zealousness, and put his life in danger.