The Gemara in Masechet Yoma (29A) says:
הרהורי עבירה קשין מעבירה וסימניך ריחא דבישרא
(Thoughts of sin are harder than sin itself, as smell of meat is more attractive than taste of meat)
According to Rashi, the text addresses the physical harm caused by sexual desire, i.e. thinking of prohibited women (sexual thinking), compared with the physical harm caused by prohibited sexual intercourse:
תאות נשים קשים להכחיש את בשרו יותר מגופו של מעשה
According to the Rabenu Bechaye (Cad Hakemach, Taharat Halev), there are many explanations for the Gemara's statement:
- The first opinion: Thought is the most spiritual thing in man, and to impair or soil it is worse than to impair or soil the material body.
- The second opinion: It is more difficult to overcome the impulse to sin caused by repetitive thought patterns than the impulse to sin caused by past physical sins that were not accompanied by continual sinful thinking.
- The third opinion: The Gemara is talking about premeditation. When a man premeditates a sin, he will make every effort to achieve his target, even if he needs to kill someone for this. While planning, he is willing to commit additional sins in order to facilitate his target sin.
- The fourth opinion (attributed to Ramban): The Gemara is talking about sinful thoughts that persist even after the sin has been committed. It is more than a simple desire. He cited a passage from Gemara Kidushin 40B, based on which he says that idle thoughts might not be acted upon and are less significant than a decision to act. Action results from a decision, not just idle thoughts. In his opinion (against the third opinion), a man will not be punished merely because of thinking or desiring; thinking and desiring is not manageable, and thoughts are often egodystonic. Against this argument, Rabenu Bechaye argued the existence of 'proactive' thinking: A man can anticipate and get into the right conditions in which no bad thoughts will come. The choice to adequately prepare for well-oriented thinking is entirely free, and whoever doesn't create the right conditions for himself is liable to punishment.
It seems that Rabenu Behaye chooses the first opinion. (I've seen this in the past: Rambam (More Nevuchim III, 8). It is a wonderful passage in the book).
See also Rabenu Yona, who cites a Hazal linked to this topic. There are cases in which the intention to sin, even if the person's plan to sin is foiled, is considered as if the sin was actually committed (in this regard, Rabenu Bechaye also cited thinking about idol worship).