Jibra`il came to Prophet Yusuf (as) while he was in prison and asked him: “O’ Yusuf! Who made you the most beautiful of all men?”
Yusuf replied, “Allah.”
Jibra`il questioned again, “Who made you the most beloved of all children in the eyes of your father?”
“My Allah,” said Yusuf.
“Who directed the caravan towards the well (into which you were thrown)?”
“My Lord,” replied Yusuf.
“Who protected you from the stone which the people of the caravan had hurled into the well?”
“Allah.”
“Who delivered you from the well?”
“My Allah.”
“Who protected you from the deceit of the ladies?”
“My Lord.”
Jibra`il finally concluded, “Allah says: What made you seek your need from someone other than Me? For this act, you shall stay in prison for seven years (for the offense of placing your trust in the king’s barman andasking him to seek your freedom from the king).”
According to another tradition, Allah revealed to him: “O’ Yusuf! Who was it who showed you that dream?”
Yusuf replied, “It was You, O’ My Lord!”
“Who protected you from the guiles of the wife of the King of Egypt?” asked Allah.
“It was You, O’ My Lord!”
Allah declared, “(Then) why did you seek help from someone else and not from Me? Had you placed your trust in Me, I would have liberated you from your imprisonment, but now that you have placed your trust in someone else, you must stay in prison for seven years.”
(After this) Yusuf wept so much in prison that his inmates became frustrated with him and it was decided that he would only weep on alternate days.( Namunah-e-Ma’arif, Volume 3, Page 280; Layaliul Akhbar, Page 92 )