The Greek New Testament in addition to most English translations of the passage treat verses 18-21 as one unit, or one paragraph. John is admonishing his followers in this paragraph to protect themselves from the slavery of sin (idolatry), which otherwise exposes one to direct demonic influence.
In the Hebrew Bible idols were correlated with demons. The following two passages are examples.
Psalm 106:34-38 (NASB)
34 They did not destroy the peoples,
As the Lord commanded them,
35 But they mingled with the nations
And learned their practices,
36 And served their idols,
Which became a snare to them.
37 They even sacrificed their sons and their daughters to the demons,
38 And shed innocent blood,
The blood of their sons and their daughters,
Whom they sacrificed to the idols of Canaan;
And the land was polluted with the blood.
Deut 32:16-17 (NASB)
16 “They made Him jealous with strange gods;
With abominations they provoked Him to anger.
17 “They sacrificed to demons who were not God,
To gods whom they have not known,
New gods who came lately,
Whom your fathers did not dread.
Other passages correlate idols with images of animals. The following passage provides one such example of how Cannanite deities were depicted in the images of animals.
Lev 17:7 (NASB)
7 They shall no longer sacrifice their sacrifices to the goat demons with which they play the harlot. This shall be a permanent statute to them throughout their generations.
Idolatry is the usurpation of divine authority. The image of the idol represents disobedience. This image stems from original disobedience in the Garden of Eden. The following graph therefore provides the self-evident model of divine usurpation, where the image of the animal replaces God.
Thus idols represent demonic power, which comes from disobedience (sin). The Apostle Paul brings this concept from the Hebrew Bible into the Christian New Testament in the following passage.
1 Cor 10:20 (NASB)
20 No, but I say that the things which the Gentiles sacrifice, they sacrifice to demons and not to God; and I do not want you to become sharers in demons.
In another passage Paul correlates idolatry with slavery. That is, slavery is correlated with idolatry.
Colossians 3:5 (NASB)
5 Therefore consider the members of your earthly body as dead to immorality, impurity, passion, evil desire, and greed, which amounts to idolatry.
Paul is not saying that immorality, impurity, passion, evil desire, and greed are demonic, but that they "add up" to idolatry. In other words, the sinner "pays obeisance" to particular addictive behaviors. While all men are sinners (Rom 3:23), some are enslaved to particular sinful behaviors.
2 Peter 2:19b (NASB)
19b . . . for by what a man is overcome, by this he is enslaved.
The enslavement to sin is the power through which demons may exercise their influence over human beings. The "idol" is therefore not only the image made with hands (traditional definition of idol), but slavery to some form of addictive, sinful behavior.
Galatians 4:7-10 (NASB)
7 Therefore you are no longer a slave, but a son; and if a son, then an heir through God. 8 However at that time, when you did not know God, you were slaves to those which by nature are no gods. 9 But now that you have come to know God, or rather to be known by God, how is it that you turn back again to the weak and worthless elemental things, to which you desire to be enslaved all over again? 10 You observe days and months and seasons and years.
The phrase, "by nature are no gods," is the same reference that Paul used in 1 Cor 8:4 and 1 Cor 10:20 in regard to demons.
In summary, idolatry encompasses not only graven images (traditional definition of idol), but also slavery to addictive sinful behaviors, which make the sinner "pay obeisance" to the power of sin. When the sinner is enslaved to some addictive sinful behavior, then is the sinner exposed to direct demonic influence, since idolatry is persistent sin (whether continually bowing to the man-made graven image or addiction to sinful behaviors). In this sense, "idolatry" usurps divine authority.
The passage (paragraph) of 1 John 5:18-21 reads as follows.
1 John 5:18-21 (NASB)
18 We know that no one who is born of God sins; but He who was born of God keeps him, and the evil one does not touch him. 19 We know that we are of God, and that the whole world lies in the power of the evil one. 20 And we know that the Son of God has come, and has given us understanding so that we may know Him who is true; and we are in Him who is true, in His Son Jesus Christ. This is the true God and eternal life. 21 Little children, guard yourselves from idols.
The Greek word for "touch" is ἅπτομαι, which, in every other instance of its usage in the Greek New Testament, means to touch something (like a cloak, garment, the eyes, etc.), but in the LXX, the word is used of Satan, who "touched" Job. That is, it was not that Satan "touched" Job so much as Satan struck him.
Job 2:5-6 (NASB)
5 However, put forth Your hand now, and touch his bone and his flesh; he will curse You to Your face.” 6 So the Lord said to Satan, “Behold, he is in your power, only spare his life.”
Other LXX passages that use the Greek word ἅπτομαι to mean strike down are 2 Sam 5:8, 2 Ki 15:5, Job 1:11-12, Job 1:19, Job 19:21, and Jer 12:14.
The Apostle John is indicating that without specific permission from the Lord, the child of God is protected from being "touched" by Satan. However, any addictive sinful behaviors (idolatry) will expose the child of God to direct demonic influence.