When the brothers first came down to Egypt, Yosef immediately accused them of being spies and jailed them for three days. The Chatam Sofer asks how Yosef could have delayed them for three days if their purpose in coming to Egypt was to collect food. It must be that Yosef knew that Yaakov still had food left. In reality, though, how could he possibly have known this?
The answer lies in the Pasuk, “VaYizkor Yosef Et HaChalomot Asher Chalam Lahem VaYomer Aleihem Meragelim Atem,” “Yosef remembered the dreams that he had dreamt about them and said, 'You are spies!'” (Bereishit 42:9). What is the connection between the dreams and Yosef's accusation that his brothers were spies? Yosef remembered that in his first dream, other bundles of wheat had bowed down to his bundle of wheat. He now interpreted this to mean that even while his brothers were bowing down to him, they and Yaakov still had food left at home. Because Yosef remembered the dream and expounded its significance, he could rationalize keeping his brothers in Mitzrayim for more time, so at this point he began his accusation.
A second question arises: of all things, why did Yosef accuse them of spying? Why not accuse them of something more severe, like murder? The Kli Yakar answers that this accusation was a strategic way to defend against his discovery. The brothers might have been tempted to go around Mitzrayim trying to find out what had happened to Yosef when he arrived as a slave. However, now that they were allegedly spies, they no longer would be able to exhibit such suspicious (and incriminating) behavior. Fabricating the claim that his brothers were spies allowed Yosef the security of knowing that they couldn't find out that he, the Mishneh LaMelech of Mitzrayim, actually was Yosef, their brother.