וְהֽוֹצֵאתָ֣ אֶת־הָאִ֣ישׁ הַה֡וּא אוֹ֩ אֶת־הָאִשָּׁ֨ה הַהִ֜וא אֲשֶׁ֣ר עָ֠שׂוּ אֶת־הַדָּבָ֨ר הָרָ֤ע הַזֶּה֙ אֶל־שְׁעָרֶ֔יךָ אֶת־הָאִ֕ישׁ א֖וֹ אֶת־הָאִשָּׁ֑ה וּסְקַלְתָּ֥ם בָּאֲבָנִ֖ים וָמֵֽתוּ׃
então trarás à tua cidade esse homem ou essa mulher que tiver feito essa coisa má, e os apedrejarás até a morte.
Or HaChaim
כי ימצא בקרבך, "If there be found amongst you, etc." The reason the Torah adds the word בקרבך, "in your midst," is to place the burden of dealing with the sinner (idolator) on the local authorities. Jews in other cities are only charged with dealing with the idolator if the people of his own city have failed to do so. This is what is meant by the words באחד שעריך, "in one of your cities." Our sages in Ketuvot 45 make use of the expression שעריך both here and in verse 5 to rule that the execution of the idolator takes place where he performed the sin and not in the city where he was sentenced to death (assuming they are not the same). The reason that the verse concludes with "which the Lord your G'd is about to give to you," is a reminder that one of the reasons G'd gave us the Holy Land is that we observe the commandment to execute idolators.
Bartenura
את השבט – the majority of a tribe that intentionally worshiped idolatry, they are not judged other than with a Jewish court of seventy one, as it is written (Deuteronomy 17:5): “You shall take the man or the woman [who did that wicked thing] out to the public place….”, You can take a man or a woman out to the public place, but you cannot take out a tribe to the public place (i.e., literally, “your gates”) other than with the large Jewish court [of seventy-one members].
Bartenura
ואין עושין עיר הנדחת – As it is written (Deuteronomy 17:5): “You shall take the man or the woman.” A man or a woman you take out to your gates (i.e., “the public place”), to the Jewish court that is in your city, but you do not take the entire city to your gates (i.e., “the public place”) other than to a special gate.
Rashi
יחרם means SHALL BE PUT TO DEATH — Why is this verse with its predicate יחרם said at all? Was not the death penalty for him (the idolator) stated in another passage: (Deuteronomy 17:5) “Thou shalt bring forth that man or that woman [who have done that evil thing … and stone them]”? But the reason is: because Scripture does not specify there for what form of worship he (the idolator) is liable to death and it merely states, “and hath gone and served other gods” — now, in order that you might not say that any kind of worship offered to idols is punishable with death, Scripture comes and definitely tells you here: “one who sacrificeth unto any god [shall surely be put to death]”, to teach you that all kinds of worship which have a certain characteristic of “sacrifice” are meant here. What is this characteristic of sacrifice? It is an act of worship performed in honour of the Lord in the “Interior” (i. e. in the Temple)! So I mean to include as punishable by death anyone offering incense and libation since these are also acts of worship performed in the Temple, and that one is liable for these acts if he performed them in honour of any idol, whether this be the usual way of worshipping it or whether this be not the usual way of worshipping it. But other forms of adoration which are shown to some idols but which are not peculiar to the worship of the idol which one happens to be worshipping, — if, e. g., one sweeps the place before the idol in its honour, or one lays the dust in front of it by sprinkling water there, or one embraces or kisses it, — are not punishable by death (cf. Sanhedrin 60b).