Praise be to Allah.
Allaah says (interpretation of the meaning):
“And indeed she did desire him, and he would have inclined to her desire, had he not seen the evidence of his Lord”
Her desire was to commit sin, but as for Yoosuf (peace be upon him), if he had not see the evidence of his Lord, he would have inclined to her desire – because of human nature – but he did not, because of the evidence mentioned.
Because he hadseen seen the evidence of his Lord, he did not incline to her desire.
Abu Haatim said: I used to recite ghareeb al-Qur’aan to Abu ‘Ubaydah, and when I reached the verse (interpretation of the meaning): “And indeed she did desire him, and he would have inclined to her desire” [Yoosuf 12:24], Abu ‘Ubayd said: This is to be understood as meaning that he saw the proof of his Lord, and so he did not incline to her desire.
Al-Qurtubi, al-Jaami’ li Ahkaam al-Qur’aan, 9/165.
Al-Shanqeeti said in Adwa’ al-Bayaan (3/58):
This may be answered from two angles:
1 – That what is meant by saying “Yoosuf would have inclined to her desire” is that a thought crossed his mind, but the influence of taqwa (piety) deflected that thought. One of them said: this is the natural inclination and the instinctive desire that is restrained by taqwa. There is no sin in that because this is something that is instilled in man and is not under his control. It says in the hadeeth that the Prophet (peace and blessings of Allaah be upon him) used to divide his time equally among his wives and treat them fairly, then he would say: “O Allaah, this is how I divide that over which I have control, so do not take me to task for that which is beyond my control” – meaning the inclination of the heart. [Abu Dawood, al-Sunan, hadeeth no. 2134.
This is like the fasting person’s inclination towards cold water and food, while at the same time his taqwa prevents him from drinking or eating whilst he is fasting.
The Prophet (peace and blessings of Allaah be upon him) said: “Whoever thinks of an evil action but does not do it, one hasanah will be recorded for him.” [Narrated by al-Bukhaari in his Saheeh, no. 6491; Muslim, no. 207]
2 – Yoosuf (peace be upon him) did not think of doing anything at all, because he was prevented from doing so because of the proof of his Lord. This view which was favoured by Abu Hasaan and others is more correct according to the rules of the Arabic language.
Then he started to quote the evidence to support the view he favoured. Based on the above, the meaning of the verse – and Allaah knows best – is that if Yoosuf (peace be upon him) had not seen the proof of his Lord, he would have inclined towards her desire, but because he had seen the proof of his Lord he did not incline towards her desire and did not think of it at all. Similarly, just thinking of something without doing it is not regarded as a sin. And Allaah knows best. May Allaah send blessings and peace upon his noble Prophet.