The Ramban and Ohr HaChaim both note the bravery of Yosef in approaching these two high ranking officers and asking them about their moods. Here is Yosef, a young slave, asking officers from Paraoh’s palace why they were sad. The question itself is somewhat puzzling; after all, they were in prison, which isn’t the most uplifting of places. The question almost seems rhetorical. Yosef, however, attune to their disposition, recognizes that something is particularly awry with these men, which he would discover is the product of their dreams from the previous night.
The Lebavitcher Rebbe (in a sicha given in 1974, summarized from Yiddish to Hebrew by Rav Yaakov Levi Ginsberg) points out, that perhaps even more impressive than Yosef’s courage, is that fact that Yosef even paid the slightest bit of attention to them and their degree of sadness. After all, Yoseph had suffered immense pain already in his life: He lost his mother at a young age, he was sold as a slave by his own brothers, hauled down to Egypt away from his beloved father, and imprisoned for a sin he had not committed. We would expect that such a person would be wallowing in his own pain, too consumed by personal sadness/frustration to be cognizant of another person’s pain.
And yet, Yosef is acutely aware of the pain of his cell-mates. Despite his own hardships, he remains attentive and sensitive to others, and inquires if there is any manner – just the slightest chance – that he can implement his G-d-given gifts to help another human being.
The Lebavitcher Rebbe explains that Yosef HaTzaddik possessed the quality of knowing that every individual’s personal mission, and the greatest happiness one can achieve, is to utilize the skills given to us by Hashem to improve the world and the lives of people around us; to wholeheartedly engage in the unique shlichus for which we were created. Yosef’s focus in life was unwavering, regardless of whether he was in a palace or a jail cell. He remained fixated on furthering his mission in life (which is how he thwarted Mrs. Potiphar’s advances), and ultimately, through Yad Hashem, his question of ‘why are you upset’ leads to his ascension to mishneh la’melech.
In the small confines of an Egyptian dungeon, Yosef notices someone in pain, gathers the courage to inquire, and uses the gifts of sensitivity and interpretive skill to eventually fulfill his Divine mission/shlichus in the most expansive manner possible.