Joseph pbuh is now surrounded with the enemies of Allah, its either the immoral act(Fahisha) or the prison,and they were the ones who’ve limited these two ways,and
Joseph did not give up these two choices,but he chose what harmed him wordly-wise and materialistically, and that is the prison, without being harmed spiritually or by
the hereafter,and that is the immoral act(Fahisha),a natural choice,and no one would have expected it except the successor of Jacob pbuh the Prophet and Messenger
The Prince of the believers Ali pbuh said: “..And for me towards Joseph is a pattern of conduct,when he said: (Lord,the prison is more to my liking than that to which they are calling me towards) and if you said that Joseph supplicated to his Lord and asked him for the prison because of the anger of His Lord, you have then disbelieved, and if you said that he needed this so His Lord doesn’t become angry upon him therefore he chose the prison,the successor is then more excusable…” 
But the question is: Is it to Allah, the rescue of Joseph from their plots limited to the prison, or are there multiple ways for his rescue from their plots,without any harm befalling him from the prison?!
(2)Bihar Al Anwar: v.29 p.438
And if Joseph was absentminded about this reality”..And if you were before this, thou too was among those who knew it not.”(1)And he didn’t pay attention that with Allah there is another way; but there is even more than one way other than the prison, to be rescued from their plots.
From Abi AlHassan AlRitha pbuh, he said: “The prisoner said to Joseph: I love you, so Joseph said: “There wasn’t a calamity affecting me except from love. If my paternal aunt loved me-she robbed me.If my father loved me-my brothers envied me.If the woman of AlAzeez loved me-she has imprisoned me”, so he said: So Joseph complained about it in the prison to Allah and said: ” ‘O’ Lord what did I deserve to be in the prison?”, so Allah inspired to him-you have chosen this when you said: Lord, the prison is more to my liking than that to which they are calling me towards, for what reason didn’t you say that good conditions (The Afya) are more to my liking than what they are calling me towards.” (2)
Isn’t Allah capable of reminding Joseph pbuh about this reality, and make him supplicate with this dua(supplication)(The good conditions (Afya) are more to my liking than
that to which they are calling me towards), besides saying :”The prison is more liking to me than that to which they are calling me towards”.
And does anybody even believe that Joseph was not able to know this reality, and he is the one that delegated his matter before when he used to be in the bottom of the well- and up to the God of Ibraheem, he did not choose to exit or even remain.
From Abi Abdullah pbuh he said: “When the brothers of Joseph placed him inside the bottom of the well, Gabriel entered to him while he was at the bottom of the well, so he said: ‘O young man, who placed you in the bottom of the well’, so Joseph said to him: ‘My brothers, because of my position to my father they envied me and so because of this they placed me in the bottom of the well’, so he said:’ Do you want to exit out of it’,so he said to Joseph: ‘That is up to the God of Ibraheem, Isaac and Jacob’, so he said: ‘The God of Ibraheem, Isaac and Jacob is saying to you’: Say” O Allah I ask You, for You have all the praises, no God but You, the Compassionate and Bestower, Maker of the skies and the earth ,the one with Exaltation and Generosity send your peace and blessings upon Muhammad and the family of Muhammad and give a relief (Faraj) to my matter and an exit
(2)Tafseer AlQummi v.1 p.354 Bihar Al Anwar v.12 p.387
and sustain me in a way to which I know and do not know”.So he supplicated to his Lord -so Allah made for him from the bottom of the well a relief to his condition, and from the plot of the woman an escape route and the King of Egypt gave him, when he did not even know.” (1)
So why was he absentminded about the saying: “That is up to the God of Ibraheem,Isaac and Jacob”?
And does anybody believe that Joseph pbuh did not deserve to be reminded by Allah, or is he pbuh not of its people, or does anybody believe that in the area of the Praised one and Most High there is stinginess from Him preferring to remind and teach Joseph His generous Prophet to supplicate by this to be saved from the deceptions and the prison all together,didn’t the Praised one and Most High send Gabriel pbuh to remind Joseph and teach him this supplication to be rescued from the bottom of the well.
Why did Allah the Praised one and Most High right now the Generous,The Clement and Intensely Merciful leave Joseph pbuh in his perplexion,and not remind him and not teach him a supplication to be rescued from the deception and the prison all together?!Why did Joseph now not find infront of his eyes a way for his rescue from the deception except the prison and did not find except this supplication “The prison is more liking to me than that to which they are calling me towards”?!!
This question and other questions during the journey of Joseph pbuh, the Most high answers him in a great verse from the verses of the Chapter of Joseph, and the Most High clarifies within it that every breath and movement and absentmindedness and remembrance and knowledge and ignorance is important to the journey of empowering and teaching Joseph pbuh, and the Most High says in this verse: “I will hold the wrist of Joseph pbuh and lead him to the empowerment and knowledge and knowing” Thus did We establish Joseph in the land, that We might teach him the interpretation of stories (and events). And Allah hath full power and control over His affairs; but most among mankind know it not.” (2)
So then, from this verse “And Allah hath full power and control over His affairs; but most among mankind know it not” we know that Joseph pbuh entering the prison occurs as being part of Divine wisdom,and of course it pours unto the empowerment for Joseph and teaching him, and even performing for his Divine message.As for the prison tied to empowering Joseph and teaching him,it was clarified beforehand from the Enlightenments. As for relating to Joseph entering the prison to perform his message, that is what I needed to clarify, and it will be summarized in matters and from them:
(1)Bihar Al Anwar v.12 p.247
1. If Joseph pbuh expounded his message from Allah outside of prison and there wasn’t any person believing in him,[he]must find another medium for preaching the message.
2.Joseph pbuh was outside of prison and was an owned slave,and no doubt that the state of an owned slave inside the prison has more freedom than outside of the prison under the authority of his Master,that is, the shackle of slaveship is more greater than the shackle of the prison.The prison bestowed for Joseph a lot of time and with a lot of free weather to expound the call about Tawheed (Monotheism).
3-In the prison everyone was in harmony, the owned slave or the free one, no one was looking at Joseph as if he was an owned slave or doesn’t deserve to be listened to.
4-The acceptance of the human being for religion and the call to obey Allah the Praised one during his uneasiness is more bigger by a whole lot rather than it being at ease and relaxation. And so we see the Most High saying: “We showed them Sign after Sign, each greater than its fellow, and We seized them with Punishment, in order that they might turn (to Us).” And indeed We will make them taste of the Penalty of this (life) prior to the supreme Penalty, in order that they may return.” Meaning to return to the truth and to Allah the Praised one, and no doubt that the prison is an uneasiness and hardship and severity according to any human being, and that is why we see that the call of Joseph towards monotheism and his message from Allah the Praised one has ripped its way towards the hearts of those who were in the prison,so a lot of them were compassionate with him and the prisoner that was rescued as this was aforementioned in the enlightenments, if it wasn’t for Joseph entering the prison only for this prisoner to believe, it would have been sufficient.
5-The call of Joseph towards Tawheed (monotheism)is comprehensive to whomever was outside the prison and whoever is in the prison,and there wasn’t a way to make his call reach pbuh inside the prison in the correct picture except by Joseph entering the prison on his own. And lastly I say: That the call of Joseph towards monotheism, did not find a place in society from where he used to be in while he was outside of prison; however, it tore its way into the hearts of the people when Joseph pbuh entered the prison. And so the call began by monothiesm with a realistic beginning, and from it[the call] are those who believed in it and want to achieve victory for it,and that prisoner who believed achieved victory by the Divine call of Joseph when he saw an appropriate chance through the vision of the King, and this believer exposed himself to danger on account of the materialistic people, while he was opposing the chieftains of the King according to their opinions since: “They said: “A confused medley of dreams: and we are not skilled in the interpretation of dreams.” (1)
And then Joseph mentions with the attendance of the King and his chieftains “But the man who had been released, one of the two (who had been in prison) and who now bethought him after (so long) a space of time, said: “I will tell you the truth of its interpretation: send ye me (therefore).” (2)
And lastly, he went to the prison and spoke to the accused Joseph pbuh and the one who imprisoned him “Azeez” of Egypt and with the attendance of the prisoners with this speech: “”O Joseph!” (he said) “O man of truth! Expound to us (the vision) of seven fat kine whom seven lean ones devour, and of seven green ears of corn and (seven) others withered: that I may return to the people, and that they may understand.” (3) Not only do they know the interpretation of the vision, but they also know about your truth and the message from Allah,and they know the oppression that had fell on you, and so the prisoner needed to believe in the mentioning of Joseph pbuh despite the possibility of danger.
And the result of this, the prisoner was the place and the condition through which the call of Joseph began a breakthrough towards monotheism, on its way to the hearts with a lot of people in Egypt, to believe in it[the call] and worship Allah, and even some of them believed- from those who were in the palace of the King-and belief in monotheism continued when Joseph pbuh expounded it in Egypt, and even in the palace of the King during the Message of Moses pbuh, and this is the believer of the people of the Pharoah during the time of Moses pbuh mentioning Joseph pbuh as a Messenger of Allah believing in him and his message: “”And to you there came Joseph in times gone by, with Clear Signs, but ye ceased not to doubt of the (Mission) for which he had come: At length, when he died, ye said: ‘No messenger will Allah send after him.’ thus doth Allah leave to stray such as transgress and live in doubt,-“ (4)