G-d told Moshe was told Bamidbar (25:4). And the Lord said to Moses, Take all the chiefs of the people, and hang them up before the Lord in the sun, that the fierce anger of the Lord may be turned away from Israel. Rashi says that this should not be understood literally that the leaders were killed but rather that the leaders should make sure that those who were involved in sexual crimes should be killed.
However it seems that this a dispute in Bamidbar Rabba (20:23)/Tanchuma (Balak 28) whether the verse means that the leaders should judge the guilty and execute them or whether the leaders are the ones who were killed. Abarbanel, Seforno, Panim Yafos, Rekanti and others say in fact that it means the leaders should be killed. Why should Moshe be told to kill the leaders of the Jewish People if they weren’t involved in the depravity? They answer because the leaders didn't protest against the sexual depravity of the people. The failure of the leaders to protest and instead remain complacent was actually a greater sin than the sin of the sexual depravity of the people and therefore the only way to prevent G‑d’s anger from destroying the people was for the leaders to be executed (those who sinned and those who failed to stop the sin). This is what motivated Pinchas in his vigilante action against the leader Zimri.
Abarbanel (Bamidbar 25:04): G-d said to Moshe, Take all the leaders and kill them in broad daylight. It was appropriate that when G-d saw this terrible sin being done openly amongst the Jewish people and the leaders and police did not even protest or criticize or punish the sinners. G-d said to Moshe it was proper to give a major punishment to the leaders for ignoring their duty for what was being done before them.













