The Gemara states that a king takes a haircut every day because it is said (Yeshaya 33:17) מֶלֶךְ בְּיָפְיוֹ תֶּחֱזֶינָה עֵינֶיךָ, your eyes will behold the King in His splendor. It is said (Bereishis 39:6) וַיַּעֲזֹב כָּל אֲשֶׁר לוֹ בְּיַד יוֹסֵף וְלֹא יָדַע אִתּוֹ מְאוּמָה כִּי אִם הַלֶּחֶם אֲשֶׁר הוּא אוֹכֵל וַיְהִי יוֹסֵף יְפֵה תֹאַר וִיפֵה מַרְאֶה, he left all that he had in Yosef’s custody and with him present he concerned himself with nothing except for the bread he ate. Now Yosef was handsome of form and handsome of appearance. Rashi writes that when Yosef saw himself ruling, he began eating and drinking and playing with his hair, so HaShem told him, “your father is in mourning and you are playing with your hair?! I will incite the bear, i.e. the wife of Potiphar, against you.”
Perhaps the meaning of Yosef “playing with his hair” is that he started taking daily haircuts because he felt that he was a king. Indeed, we see further on that when Yosef was taken out of jail to interpret Pharaoh’s dreams, it is said (Ibid 41:14) וַיִּשְׁלַח פַּרְעֹה וַיִּקְרָא אֶת יוֹסֵף וַיְרִיצֻהוּ מִן הַבּוֹר וַיְגַלַּח וַיְחַלֵּף שִׂמְלֹתָיו וַיָּבֹא אֶל פַּרְעֹה, so Pharaoh sent and summoned Yosef, and they rushed him from the dungeon. He shaved and changed his clothes, and he came to Pharaoh. Rashi writes that he took a haircut in honor of the king. The simple explanation is that he took a haircut in honor of coming before Pharaoh, but on a deeper level we can explain this to mean that Yosef took a haircut with the knowledge that after successfully interpreting Pharaoh’s dreams he would become a ruler .