I will not sully the pages of this site by describing the truly horrid, lurid, disgusting and degrading practices of child sacrifice in various forms that existed in association with the pagan god, Molech.
The question here concerns the reason for a law banning such appalling, satanic practices in Lev 18 rather than the more logical place such as Lev 20:2-5.
The answer is a simple as it is "kinky": such child sacrifice was sometimes associated with cultic sexual practice; that is, some pagan practices use child sacrifice as a means for arousing sexual desire. As such it is entirely appropriate to include at least a passing reference to these ideas amongst the laws banning deviant sexual behaviour.
I believe that this is conformed by the addition in the same verse, "neither shalt thou profane the name of thy God."
Ellicott also observes:
(21) And thou shalt not let any of thy seed.—Literally, And thou shalt
not give any of thy seed. Those who violate the sanctity of the
marriage ties will readily sacrifice their children. Hence the
prohibition to offer up their children to idols follows the law about
unchastity.
The Cambridge commentary offers another reason:
- A more suitable position for this precept would be at the end of the laws in Leviticus 18:7-23. It occurs in a developed form in
Leviticus 20:2-5. Its sudden interposition may be accounted for by
remembering the condemnation of idolatry under the figure of
unfaithfulness to the marriage tie (cp. the expressions in Leviticus
20:5 a), see Jeremiah 3:1 ff. For the worship of Molech (Milcom), the
god of the Ammonites, see Barnes (C.B.) on 1 Kings 11:5.