וַיֹּ֨אמֶר יְהוָ֜ה אֶל־מֹשֶׁ֗ה קַ֚ח אֶת־כָּל־רָאשֵׁ֣י הָעָ֔ם וְהוֹקַ֥ע אוֹתָ֛ם לַיהוָ֖ה נֶ֣גֶד הַשָּׁ֑מֶשׁ וְיָשֹׁ֛ב חֲר֥וֹן אַף־יְהוָ֖ה מִיִּשְׂרָאֵֽל׃
האָט גאָט געזאָגט צו משהן: נעם אַלע הױפּטלײַט פֿון דעם פֿאָלק, און הענג זײ אױף פֿאַר גאָט אַקעגן דער זון, און דער גרימצאָרן פֿון גאָט װעט זיך אָפּקערן פֿון ישׂראל.
Rashi
קח את כל ראשי העם TAKE ALL THE HEADS OF THE PEOPLE, to judge those who worshipped Peor (Sanhedrin 35a),
Midrash Lekach Tov
"And the Lord said to Moses, 'Take all the leaders of the people and hang them before the Lord, facing the sun, that the fierce anger of the Lord may turn away from Israel.'" If the people sinned, what was the sin of the leaders? Rather, the Holy One, blessed be He, said to them, "Appoint many courts for them, so that the anger of the Lord will subside, and hang them before the Lord." How do we know that hanging is meant? As it is stated, "And hang them before the Lord in the valley of the shadow of death." Opposite the sun. From here we learn that judgments regarding capital offenses are not held at night. Opposite the sun, based on witnesses. Similarly, it is stated, "If the sun has risen upon him, he shall be guilty." Another interpretation: Opposite the sun, so that the sun does not shine upon them. And similarly, it says, "His carcass shall not remain overnight upon the tree." Another interpretation: Opposite the sun, so that every cloud departs from it, and the sun shines upon it.
Sforno
נגד השמש, so that the people would observe the execution of the idolaters and by not protesting their punishment achieve atonement. This would help them achieve atonement for having sinned by not protesting the sinners’ conduct beforehand.
Or HaChaim
צוטריטלעך נאָר פֿאַר פּרעמיום־מיטגלידערRabbeinu Bahya
צוטריטלעך נאָר פֿאַר פּרעמיום־מיטגלידערSiftei Chakhamim
צוטריטלעך נאָר פֿאַר פּרעמיום־מיטגלידערRav Hirsch
צוטריטלעך נאָר פֿאַר פּרעמיום־מיטגלידערRashi
והוקע אותם AND HANG THEM — those who worshipped it (not the heads of the people).