ذَٰلِكَ لِيَعْلَمَ أَنِّى لَمْ أَخُنْهُ بِٱلْغَيْبِ وَأَنَّ ٱللَّهَ لَا يَهْدِى كَيْدَ ٱلْخَآئِنِينَ
Commentary:
The words of this and the following verses were uttered by Joseph and not by the seducing woman as supposed by some commentators. The pronoun "him" in the clause لم اخنه (I was not unfaithful to him) refers to Potiphar. The verse shows Joseph as stating the object for which he had caused this enquiry to be held, which was to clear himself of the possible charge that he had behaved faithlessly towards his master, Potiphar.
The words "the unfaithful" here refer to those who had plotted against Joseph. As Joseph was a Prophet of God, the plotters against him could not succeed, and hence God caused their plot to be exposed and defeated.