The proud and precocious Joseph was brought down - first to
the pit, then into servitude in Egypt, and finally to the dungeon. What a
fall from a place high in one's esteem to a place very low in the world.
Yet, God was with Joseph.
So, it was not Joseph who was sad in prison. It was the cupbearer and the baker, sent there on suspicion by the king, who had dreams without interpretation or an interpreter.
Relying on his Source, Joseph offered to help explain the dreams, believing and saying, "Are not interpretations from God?"
Each of the two dreamers would be called to "lift up the head" - both brought to account and to justice. One would be restored to dignity and position, while the other would be punished literally to the prescription.
Those who are high in station but low with God are lost. Those who are with God are comforted when down, discern the meaning of the lifting of the head, and will ultimately rise.