Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:12:56

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.  

Thus, in the same way that We were graceful towards Him by delivering him from prison, We established Joseph in the land, the land of Egypt, that he may settle in it wherever he wished, after ˹having suffered˺ hardship and imprisonment. According to the story, the king crowned him, gave him a signet-ring to wear, and appointed him in place of the Court officer, whom he removed from his position, and who later died; and so he ˹the king˺ made him ˹Joseph˺ take the latter’s spouse as a wife. He ˹Joseph˺ discovered that she was ˹still˺ a virgin and she bore him two children. He ˹Joseph˺ established justice in Egypt and people became subject to him. We confer Our mercy on whomever We will and We do not waste the wage of the virtuous.
القرآن:١٢:٥٦

وَكَذَٰلِكَ مَكَّنَّا لِيُوسُفَ فِي الْأَرْضِ يَتَبَوَّأُ مِنْهَا حَيْثُ يَشَاءُ ۚ نُصِيبُ بِرَحْمَتِنَا مَنْ نَشَاءُ ۖ وَلَا نُضِيعُ أَجْرَ الْمُحْسِنِينَ  

{وكذلك} كإنعامنا عليه بالخلاص من السجن {مكنَّا ليوسف في الأرض} أرض مصر {يتبوّأُ} ينزل {منها حيث يشاء} بعد الضيق والحبس وفي القصة أن الملك توَّجه وختَّمه وولاه مكان العزيز وعزله ومات بعد، فزوجه امرأته فوجدها عذراء وولدت له ولدين، وأقام العدل بمصر ودانت له الرقاب {نصيب برحمتنا من نشاء ولا نضيع أجر المحسنين}.