In the first sentence of the second verse (22), it is said: وَلَمَّا بَلَغَ أَشُدَّهُ آتَيْنَاهُ حُكْمًا وَعِلْمًا (And when he reached at the prime of his age, We gave him wisdom and knowledge ... ).
At what age did he reach the prime of his age? In this, commentators differ. Sayyidna Ibn 'Abbas, Mujahid and Qatadah رحمۃ اللہ علیہم say that his age was thirty three years. Dalhhak jw SII ,~ ~j puts it at twenty, and Hasan al-Basri (رح) at forty. However, all of them agree that the bestowing of wisdom and knowledge upon him referred to at this place means the bestowal of Nubuwwah, the station of prophethood. This also tells us that Sayyidna Yusuf (علیہ السلام) was invested with Nubuwwah much later than his arrival in Egypt - and the Wahy (revelation) sent to him while he was in the depth of the well was not the Wahy (revelation) technically identified with Nubuwwah. Instead of that, it was a revelation in the literal sense which can also be sent to non-prophets - as it has appeared in the case of the mother of Sayyidna Musa (علیہ السلام) ، and about Sayyidah Maryam.
In the second sentence of the second verse (22), it was said: وَكَذَٰلِكَ نَجْزِي الْمُحْسِنِينَ (and this is how We reward those good in deeds). The sense is that delivering Sayyidna Yusuf (علیہ السلام) from elimination and making him reach the office of power and honour was an outcome of his righteousness, fear of Allah and good deeds. This was something not restricted to his person alone. In fact, whoever acts the way he did, shall receive the blessings of Allah in the same fashion.