Vayikra / Leviticus 17:7 · Drash
וְלֹא־יִזְבְּחוּ עוֹד אֶת־זִבְחֵיהֶם לַשְּׂעִירִם אֲשֶׁר הֵם זֹנִים אַחֲרֵיהֶם חֻקַּת עוֹלָם תִּהְיֶה־זֹּאת לָהֶם לְדֹרֹתָם׃
And they shall no longer offer their sacrifices to the goat-demons after which they go astray. This shall be a statute forever for them throughout their generations.
Drash דְּרָשׁ
The goat in the wilderness is no offering
When you see a rite whose meaning you do not understand, it is easy to invent an explanation for it, sometimes a wholly wrong one.
Kli Yakar: this law comes right after the chapter on Yom Kippur (the Day of Atonement), so that heretics would not say the goat is sent into the wilderness to the demons. The goat is no offering at all. And one who slaughters outside the Sanctuary for these demons draws the power of the sword and killing, so "blood shall be counted to that man."
How Kli Yakar explain it
Kli Yakar And they shall no longer offer their sacrifices to the goat-demons
The Torah placed this section here because heretics might err and say that the goat is sent into the wilderness for the se'irim (שְׂעִירִים, the goat-demons), Heaven forbid. So it at once warned them against slaughtering outside the Sanctuary and taught that the Eternal, on the contrary, wanted to keep them from sacrificing to the se'irim, which they had done before: for it says "no longer" (עוֹד). And the goat is not worship and not an offering, but the portion of Samael. So Ramban explained too (Vayikra / Leviticus 16:8), these are his words: "The Holy One, blessed is He, commanded that we send a goat into the wilderness to the angel who governs the desolate places. For on him depend the stars of the sword, blood, wars, wounds, blows, strife and ruin, and in sum, he is the soul of the heavenly circle (גַּלְגַּל) of Mars. Of the nations his portion is Esav (Esau), the people that inherited the sword and wars. Of the animals, the he-goats (שְׂעִירִים) and the goats. And in his portion too are the demons, called harmers and se'irim." And the master writes about this at length there. Here I can use this to explain what is said of slaughtering outside the Sanctuary: "blood shall be counted to that man" (Vayikra / Leviticus 17:4). Rashi explained: as one who has shed human blood. And one may ask: what does slaughtering outside the Sanctuary have to do with shedding human blood? But one who slaughters outside for the se'irim draws power from Mars, which sends the sword and killing. So it is rightly said "blood shall be counted to that man": he is truly counted as one who sheds blood, because this is the power of his god. And this is a precious explanation.
Takeaway
Se'irim (שְׂעִירִים) means "goats," and demons are called so too (the words of Ramban in this passage). Hence the fear that the goat (שָׂעִיר) sent into the wilderness on Yom Kippur would be taken for an offering to them (Vayikra / Leviticus 16:8–10).
Samael in the midrash is the accusing angel. Ramban quotes a midrash there (Pirkei DeRabbi Eliezer 46): on Yom Kippur Samael is given the goat as a bribe, so that he does not spoil the offering of Israel.
The words "a precious explanation" (פֵּרוּשׁ יָקָר) hold the same word "precious" (יָקָר) as the name of the book "Kli Yakar" (כְּלִי יָקָר), "a precious vessel". These two words stand in a verse: "a precious vessel are lips of knowledge" (Mishlei / Proverbs 20:15).
The heavenly circle (גַּלְגַּל), literally "wheel". In the medieval picture of the world each planet moves on its own heavenly circle, Mars on the fifth, and the stars and circles have a soul and knowledge (Mishneh Torah, Foundations of the Torah 3:1, 3:9).