Numbers 25:17, Harass … and smite them. Midian is symbolic of the immoral pleasures of the society that surrounds the people of YHVH and that will subvert and overtake the righteous if left unchecked. YHVH commanded Israel to constantly harass and attack the Midianites for their subversion of Israel sexually.
The best defense is a strong offense.
As The ArtScroll Stone Edition Chumash points out, harassing the Midianites was to be an on-going state of mind (p. 877).
Likewise, fighting the sin that would attempt to gain entrance into our lives must be a constant state of mind. YHVH commanded Israel to harass the Midianites and then to smite them. When sin arises, because our offensive and defensive positions against sin are secure, we will be ready to smite the sin that dogs us.
What are you (especially you men) doing to combat the sexual enticements of the surrounding wicked and perverse generation? What do you watch on television or view on the internet? Do you listen to sexually suggestive or downright immoral music? Are your conversations with your friends and coworkers always clean and pure? Do you allow your eyes ever to see anything that is sexually explicit? Do you vigorously and aggressively confront it for the evil that it is and take a stand against it both in your heart and mind and do so openly?
As YHVH commanded Israel to view Midian as the enemy because of their lust for immoral pleasure, so we must despise the world around us as our enemy in this regard for its debauchery and idolatry. (Read 1 Cor 10:3–5.)
In reality, we need to come to hate and despise sin at all times (as does YHVH) rather than to toy with it. (See Pss 45:7; 97:10; 101:3; 119:104 ; Prov 8:13; Amos 5:15; Rom 12:9 cp. Ps 34:4;Heb 1:9.)