Allah, may He be glorified and exalted, does not enjoin evil
Question

                When I memorized Soorat Yoosuf, this verse stuck in my mind: “So when they took him [out] and agreed to put him into the bottom of the well... But We inspired to him, ‘You will surely inform them [someday] about this affair of theirs while they do not perceive’” [Yoosuf 12:15]. Allah inspired the brothers of Yoosuf to throw him into the well, and they did not perceive until he ultimately became a king. So this wrong deed that they committed was not a wrong deed; rather it was divinely inspired, so whenever I commit any sin or error, I have started to say: perhaps this is inspiration to something the purpose of which I am not aware, or to something in the future. How can I distinguish between them?
Praise be to Allah.Firstly:
What the brothers of Yoosuf did of wronging their brother was not done on the basis of inspiration from Allah, may He be exalted; rather it stemmed from the promptings of their own souls, as their father Ya‘qoob (peace be upon him) described their situation, as mentioned in the verse in which Allah, may He be exalted, said (interpretation of the meaning):
“And they brought upon his shirt false blood. [Jacob] said, ‘Rather, your souls have enticed you to something, so patience is most fitting. And Allah is the one sought for help against that which you describe’”
[Yoosuf 12:18].
These brothers admitted that they had done wrong. Allah, may He be exalted, said (interpretation of the meaning):
“They said, ‘By Allah, certainly has Allah preferred you over us, and indeed, we have been sinners.’
He said, ‘No blame will there be upon you today. Allah will forgive you; and He is the most merciful of the merciful’”
[Yoosuf 12:91-92].
In the end, Yoosuf (peace be upon him) said:
“And he raised his parents upon the throne, and they bowed to him in prostration. And he said, ‘O my father, this is the explanation of my vision of before. My Lord has made it reality. And He was certainly good to me when He took me out of prison and brought you [here] from bedouin life after Satan had induced [estrangement] between me and my brothers. Indeed, my Lord is Subtle in what He wills. Indeed, it is He who is the Knowing, the Wise”
[Yoosuf 12:100].
This verse clearly states that what happened with Yoosuf was due to the Shaytaan inducing or creating estrangement between him and his brothers.
With regard to the verse in which Allah, may He be exalted, says “So when they took him [out] and agreed to put him into the bottom of the well... But We inspired to him, ‘You will surely inform them [someday] about this affair of theirs while they do not perceive [your identity]’” [Yoosuf 12:15], this clearly states that the inspiration came to Yoosuf (peace be upon him) – “But We inspired to him” – and not to his brothers.
There is nothing in the verse to suggest that the inspiration came to the brothers of Yoosuf.
Allah, may He be exalted, does not enjoin evil deeds such as wrongdoing and injustice; rather He enjoins justice and fairness.
Allah, may He be exalted, says (interpretation of the meaning):
“Say, ‘Indeed, Allah does not order immorality. Do you say about Allah that which you do not know?’
Say, [O Muhammad], ‘My Lord has ordered justice and that you maintain yourselves [in worship of Him] at every place [or time] of prostration, and invoke Him, sincere to Him in religion.’ Just as He originated you, you will return [to life]”
[al-A‘raaf 7:28-29].
On the basis of this verse, the scholars explained the verse in which Allah, may He be exalted, says (interpretation of the meaning):
“And when We intend to destroy a city, We command its affluent but they defiantly disobey therein; so the word comes into effect upon it, and We destroy it with [complete] destruction”
[al-Israa’ 17:16].
The mufassir Shaykh Muhammad al-Ameen ash-Shinqeeti (may Allah have mercy on him) said:
With regard to the meaning of the words “We command its affluent” in this verse, there are three views that are known to the scholars of tafseer:
The first view – which is the correct view, as it is supported by the Qur’an, and it is the view of the majority of scholars – is that the command in this verse “We command” refers to the command or instruction that is the opposite of forbidding, and that what is enjoined in this command is not mentioned, because it is obvious; what is meant is “We command its affluent
to obey Allah and affirm His oneness, and to believe in His Messengers and follow what they brought. “but they defiantly disobey therein” that is, they rebel and do not obey the command of their Lord, and they disobey Him and disbelieve in His Messengers, “so the word comes into effect upon it”, that is, the warning becomes due, “and We destroy it with [complete] destruction” that is, we destroy it and eradicate it completely. The structure of the original Arabic text indicates that the destruction that is sent upon them is thorough and far-reaching.
This view, which is the correct view regarding this verse, is supported by many other verses, such as the verse in which Allah says (interpretation of the meaning), “And when they commit an immorality, they say, ‘We found our fathers doing it, and Allah has ordered us to do it.’ Say, ‘Indeed, Allah does not order immorality…” [al-A‘raaf 7:28]. The fact that Allah, may He be glorified and exalted, has clearly stated that He does not enjoin immorality clearly indicates that the words “We command its affluent but they defiantly disobey therein” mean: We command them to obey Us, but they disobey. It does not mean, We command them to commit evil, so they commit evil, because Allah does not enjoin immorality.
End quote from Adwaa’ al-Bayaan (3/574-575).
With regard to the meaning of the verse, there are other opinions, but we do not have the space in this answer to mention them and discuss them.
Secondly:
Thinking that sins may be a way that leads to goodness is a grave error and wrong thinking, and is contrary to common sense. It is pure confusion and whispers from the accursed Shaytaan, and it poses an obvious danger to the Muslim’s ‘aqeedah (belief) and religious commitment. It is whispers from the Shaytaan aimed at making the commission of sins appear to be of little significance.
Happiness in this world and the hereafter cannot be attained except by having faith and doing righteous deeds. Bad deeds bring harm upon the doer of those deeds. This is a matter concerning which there cannot be any doubt or hesitation, and this is the message with which Allah, may He be exalted, sent all His Messengers.
Allah, may He be exalted, says (interpretation of the meaning):
“And We send not the messengers except as bringers of good tidings and warners. So whoever believes and reforms - there will be no fear concerning them, nor will they grieve.
But those who deny Our verses - the punishment will touch them for their defiant disobedience”
[al-An‘aam 6:48-49].
So believing that Allah, may He be exalted, inspires His slaves to do bad deeds in order to attain what is good is definitely an incorrect notion and there is the fear that because of this incorrect belief, a person may start with minor sins then move on to major sins, and to the worst of major sins – we seek refuge with Allah from that.
Allah, may He be exalted, honoured Yoosuf (peace be upon him) with the highest status in this world because of how well he obeyed Allah, may He be exalted, and not because of the sin of his brothers.
Allah, may He be exalted, says (interpretation of the meaning):
“And thus We established Joseph in the land to settle therein wherever he willed. We touch with Our mercy whom We will, and We do not allow to be lost the reward of those who do good”
[Yoosuf 12:56].
Imam at-Tabari (may Allah have mercy on him) said:
(That is,) thus We established Yoosuf in the land – the land of Egypt – “to settle therein wherever he willed”, that is, so that he could settle wherever he wished in the land of Egypt, after having been imprisoned then suffered hardship.
“We touch with Our mercy whom We will” of Our creation, as we touched Yoosuf therewith, and established him in the land after he had endured slavery and imprisonment, and after having been thrown into the dry well.
“and We do not allow to be lost the reward of those who do good” that is, We do not cause to be lost the reward of the one who does good, obeys his Lord, does what He enjoins and refrains from what He forbids, just as We did not cause to be lost the reward of Yoosuf’s deeds, for he did good deeds and obeyed Allah.
End quote from Tafseer at-Tabari (13/220).
Conclusion: If the Muslim commits a sin, then it is from the promptings of his own soul and the Shaytaan, so he must hasten to repent, so that he may be saved from its consequences.
Beware of being deceived by the Shaytaan, and beware of his whispers and promptings. Remember Allah a great deal, recite His Book, keep company with righteous people and attend the gatherings of people of knowledge and those who remember Allah. Keep yourself busy with learning about the truth and adhering to it, and with doing acts of worship; do not leave yourself with nothing good to do, lest you become distracted by that which is of no benefit and may even harm you in both your religious and worldly affairs.
And Allah knows best.