So, his Lord accepted his prayer and turned their guile away from him. Surely, He is the All-Hearing, the All-Knowing.
To protect him from the guile of these women, Allah Ta ala made his own wise arrangements. Though the ` Aziz of Misr and his inner circle was already convinced of the great spiritual qualities of Sayyidna Yusuf (علیہ السلام) his piety, fear of Allah and chastity, but rumours of the incident had started circulating in the city. To put a check on this, they found it expedient to confine Sayyidna Yusuf (علیہ السلام) into the prison for a certain period of time so that there remains no source of any doubt in the concerned family, and that the talk of the town too dies out in due course.
Tazkirul Quran
Maulana Wahiduddin KhanOn ayahs 34–35
Certain ladies of noble families were invited by Zulaykha to meet Joseph and they saw in him a handsome young man. Joseph also could have seen these ladies as a means of satisfying the desires of his lower self. But even in the most exciting of circumstances, he did not see them as such. The ladies were all so thrilled by his extremely charming personality, that, in their extreme state of absorption, they injured their hands with knives while cutting fruit. But Joseph’s whole attention was directed towards God. God’s greatness and Majesty so dominated his senses that nothing could divert his attention. What a difference there is between one human being and another.
Uthmani text of the Madinah mushaf (King Fahd Complex). Translation: Saheeh International. Tafsir via Quran.com.