"And all the congregation of the children of Israel journeyed from the wilderness of Sin" (Exodus 17:1). According to the order of our exposition we have learned that the enemy comes only on account of sin and on account of transgression.
The Enemy Comes Only on Account of Sin
Mekhilta DeRabbi Shimon Ben Yochai 17:1
ויסעו כל עדת בני ישראל ממדבר סין לפי דרכינו למדנו שאין השונא בא אלא על החטא ועל העברה: