Zoveach laelohim yacharam bilti lעHashem l'vado ... one who offers to other gods shall be destroyed, one may only [offer] to G-d alone (Shemos 22:19)
There are many methods of categorizing the mitzvot of the Torah: e.g., mitzvos aseh and lo sa’aseh [mitzvos requiring an action or refraining from an action] or bein adam laMakom and bein adam l’chaveiro [between man and G-d and between man and man]. Mitzvos can also be categorized by type. Rav Hirsch refers to three divisions: eidos - ritual mitzvos like taking the lulav and esrog on Sukkos or eating matzah on Pesach - chukim - mitzvos that are ordained by G-d and whose reason is untenable - e.g., parah adumah [the red heifer] or sha’atnez [the prohibition of mixing linen and wool] - and mishpatim - mitzvos necessary for society to function smoothly [e.g., the prohibition of stealing, murder, incest or returning lost objects]. Often, we find entire parshios of the Torah dealing with one area of mitzvos; e.g., our parashah, parashas Kedoshim in Sefer Vayikra, and parashas Shoftim and Ki Tetzeh in Sefer Devarim deal primarily with the area of mitzvos that enable society to govern itself. While there are other subjects that are also presented, there is usually some kind of clear delineation between the areas.
For example, in this week’s parashah, the Torah deals with the laws governing servants, maidservants, murder, accidental death, kidnapping, inflicting injury directly or through one’s property, theft, witchcraft, bestiality, the mitzvah quoted at the beginning of this essay, the proper treatment of converts, collections of loans et al. The Talmud, in a different context, questions whether the juxtaposition of seemingly unrelated laws has any halachic significance and offers a difference of opinion as to whether concurrence of subjects is only significant in Sefer Devarim or has meaning everywhere in the Torah. However, even the opinion that semuchim - juxtaposition of subjects - is only significant in Devarim would agree that this limitation is only in terms of deriving halachot from one area to another by use of hekesh. All would agree that the Torah must have had some reason for the connection between concurrent teachings organized in a single chapter. For example, while the law forbidding witchcraft and the law forbidding bestiality may not share common halachot, the prohibitions themselves are clearly related and it is thus logical why they are taught in one parashah.
However, it is somewhat difficult to understand the connection between the mitzvah of not offering sacrifices to g-ds other than Hashem to the mitzvos that follow of not causing distress to a convert, to a widow or to an orphan. The relationship between the latter three is fairly obvious; each of them has no one to protect their interests and as such, G-d takes special interest in their welfare. Idolatry, however, seems to be totally unrelated to this subject and could have been more logically brought in connection to the mitzvoth of Elokim lo s’kallel venasi b’amcha lo sa’or - You shall not demean Hashem and a prince among your nation you shall not curse (ibid. 22:27).
Ibn Ezra explains that the prohibition of serving idolatry is addressed here to the converts mentioned in the next verse; i.e., you are welcome to join the nation provided that you renounce your ties to other gods. Chizkuni supports this by noting that both witchcraft and bestiality, mentioned beforehand, are attributes of the nations of Canaan , the people most likely to want to convert so as to avoid banishment from their lands or death if they fought.
Ramban strongly rejects this and writes that the reference here is to the Celestial angels who are referred to as Elokim (see Tehillim 86:8) or Eilim (see Shemos 15:11). In his view it is easy to mistake G-d’s powers [the angels] for G-d Himself and make them the object of our worship. We do so because we want to create a G-d with whom we are comfortable, making Him in the image that fits our needs. We prefer a G-d whose vision is limited to the areas where we are not afraid to have our actions exposed. If He is also watching over the converts, widows and orphans, it means that He is Omnipresent and not subject to our whims. This is the essence of the structure of Jewish living and is thus very much at home in this parashah.