This story is related to trials whether it is for Joseph, his brothers or his father Jacob. Verse 76 refers to the same:
“Thus We planned for Joseph. He could not take his brother by the law of the king (as a slave) except that God willed it. We raise the status of whoever We please and above every one endued with knowledge is God.”
This dispels the accusation that Joseph accused his brother of theft for it was but a test for him (Reflect deeply) This is why we cannot doubt the integrity and chastity of this great apostle.