It is known that at the first time Joseph ask to return the money that his brother paid for the grains to their bags. Joseph was a leader of the Egypt nation. The money he got for the grains belongs to the Egyptians. He practically gave them the grains for free on the expense of the Egyptians. Did he have the right to do it?
It's written in parashat Vaygash (Bereshit 47:20) the following:
וַיִּ֨קֶן יוֹסֵ֜ף אֶת־כָּל־אַדְמַ֤ת מִצְרַ֙יִם֙ לְפַרְעֹ֔ה כִּֽי־מָכְר֤וּ מִצְרַ֙יִם֙ אִ֣ישׁ שָׂדֵ֔הוּ כִּֽי־חָזַ֥ק עֲלֵהֶ֖ם הָרָעָ֑ב וַתְּהִ֥י הָאָ֖רֶץ לְפַרְעֹֽה׃
English: "So Joseph gained possession of all the farm land of Egypt for Pharaoh, every Egyptian having sold his field because the famine was too much for them; thus the land passed over to Pharaoh."
So he literally bought the Egyptian land for the government, so the land and the grains were his property, therefore he had the right to do so.