When Satan tempted Eve in the garden in Genesis 3, that was really the first battle for the mind. In Genesis 3:22 it says, "And the LORD God said, Behold, the man is become as one of us, to know good and evil: and now, lest he put forth his hand, and take also of the tree of life, and eat, and live for ever:" The problem was that man was not knowledge itself but it was the knowledge of evil was soon implanted. All because of this one action that every person ends up getting ungodly thoughts the moment they enter the age of accountability. If there were no impure thoughts then there would be no sin but the knowledge of evil is there in the minds of every human being today.
The mind is a constant battlefield aside from the evil of the human heart. When Jesus warned about adultery and murder, He had already mentioned that hatred makes you guilty of breaking God's standard for murder and lusting after a woman makes you guilty of breaking God's standard of adultery. Why people do their sin is because they have sinful thoughts. Every intentional act of murder starts out with an ill thought against the victim then that ill thought is implemented towards the victim. Nobody does anything sexually immoral if the mind is not fed with such sexually immoral thoughts. Would have David just turned away from the sight of Bathsheba washing herself, he would have not fallen into adultery. Joseph resisting Mrs. Potiphar was because he guarded his thoughts from such evil.
2 Corinthians 10:5-6 states, "Casting down imaginations, and every high thing that exalteth itself against the knowledge of God, and bringing into captivity every thought to the obedience of Christ; and having in a readiness to revenge all disobedience, when your obedience is fulfilled." The only way to win against sinful thoughts is to bring them to Christ. After all, Ephesians 2:10, 1 Corinthians 6:11 and Titus 2:11-14 gives God's grace as a remedy against sinful behavior. It is not by might, not by power but by the Holy Spirit such evil thoughts can be won against.