The 6th prohibition is that we are forbidden from serving an idol even in a manner other than one of the four types of service which we have mentioned. This is upon condition that it is served k'darkah, i.e. in the way this idol is customarily served — such as excreting to [the idol] P'or, or throwing a stone at Merkulis.
The source of this commandment is G‑d's statement (exalted be He), "[Do not bow down to them] or serve them."
In the words of the Mechilta, "[The two phrases,] 'Do not bow down to them or serve them,' constitute two separate prohibitions: to serve is one and to bow down is another."
Therefore, one who threw a stone at P'or or excreted to Merkulis does not transgress [this prohibition] since it is not the customary manner of service, and G‑d Al‑mighty (exalted be He) stated, "[Be careful lest you try to find out about their gods saying,] 'Now, how do these nations worship their gods? I would also like to try [such practices].'"
One who transgresses this prohibition intentionally is punished by death by stoning or kares, and if unintentionally, he must bring a sacrifice.
The details of this mitzvah have also been explained in the seventh chapter of Sanhedrin.
There it is it asked why the punishment of kares is mentioned three times in reference to idolatry, and the answer is given: one is for serving k'darkah [in the customary manner], one is for serving lo k'darkah [in an uncustomary way], and one is for serving the idol Molech. This means to say that anyone who serves any idol in any manner is punished by kares if it is served k'darkah, i.e. in the customary manner, such as excreting to P'or, throwing a stone at Merkulis, or cutting one's hair to K'mosh. Similarly, anyone who serves any idol in one of the four types of service [mentioned in N5] is punished by kares, even if the idol is not customarily served in that manner, such as bringing a sacrifice to P'or or bowing down to Merkulis. This is called lo k'darkah. The third case of kares is one who passes [some of his children] over the fire to Molech, as we will explain.