(ספר שערי תשובה (שער ג' אות מא
**
( ולא תתורו אחרי לבבכם ואחרי עיניכם (במדבר טו
הזהרנו בזה שלא לחשוב לעשות עבירה וכל דבר פשע וחטא
Shaarei Teshuvah [Gates of Repentance] Gate 3:41
[loosely translated]...and go not about after your heart and after your eyes...
We are thus warned not to contemplate doing any type of sin.
How does this not contradict the saying of the Gemara (Kiddushin 40A) which says, “Machashavah ra’ah ein Hakodosh Baruch Hu metzarfah lema’aseh” — “If one contemplates sinning, Hashem does not regard the bad thought as a deed.” This seems to say that, Hashem will not punish one for a sinful thought alone if it was not actually followed up with committing the sin.