Shaarei Teshuvah
“Be on your guard against anything bad” (Deuteronomy 23:10). They, may their memory be blessed, explained (Ketuvot 46a), “A person should not think [impure] thoughts by day and thereby come to impurity by night” - and even though his thought is not to [follow it up with action]. And it is something learned from its [context]. As after it, it is written (Deuteronomy 23:11), “If anyone among you has been rendered unclean by a nocturnal emission.”