While many (see for example, Sarna, 1989, p. 276) understood that 40:1 and 40:2 are referring to the same people, more likely, 40:1 is referring to some subordinates who sinned against the king and most likely they were killed, as possibly Pharaoh thought they had tried to kill him. 40:2 is then referring to their superiors that they did not sin directly against the king but Pharaoh was angry at them because he blamed them for their subordinates who sinned. Thus, the chief cupbearer and the chief baker were not killed, but were sent to prison. Eventually Pharaoh would decide that the chief cupbearer was not responsible for his subordinate’s action while the chief baker was responsible, and hence the chief cupbearer returned to his position, while the chief baker was killed, 40:21,22.
40:3 records that the chief cupbearer and chief baker happened to have been imprisoned in the same prison where Yosef was imprisoned, and 40:4 records that the warden of the prison put Yosef, his second in command, 39:22, in charge of attending his special prisoners, the chief cupbearer and the chief baker.
40:5,6 records that each of the special prisoners had a dream, but they were distraught. In the case of the chief baker, his dream was ominous since it included birds eating from the top of his head, 40:17, but what was ominous about the dream of the cupbearer? The answer is that the dream of the cupbearer included grapes being pressed, va-eschat, 40:11, which might have insinuated that the cupbearer was going to be killed.
40:7,8 records that Yosef asked the two men why they were upset, and when they said it was due to their dreams, Yosef, with his usual self-confidence, told him that he would be able to interpret their dreams.
40:9-11 records the dream of the chief cupbearer, and as occurs in the three sets of dreams in the story of Yosef, the first dream in each set of dreams has two distinct elements that are not in the second dream of the set.
The first distinct element in the chief cupbearer's dream is that his dream is longer than the chief baker's dream and has apparently extraneous information to the interpretation of the dream. In this dream, the cupbearer saw a vine with three branches, the vine had shoots, then flowers and then the clusters ripened into grapes, 40:11. While the three branches are important to understanding the timing of the dream, the growth of the grapes (the shoots, the flowers and the clusters) is unnecessary for the interpretation of the dream that the chief cupbearer would return to his job. It would have been sufficient for the cupbearer to have dreamt that he took grapes from three branches and squeezed them into Pharaoh’s cup.
Instead, as by the other sets of dreams, this extra information was for Yosef. The three stages in the development of the grapes correspond to the three stages in the development of Yosef. First Yosef developed in his father’s house, then he developed working for Potiphar, and then he developed working in the prison. With these three experiences he was ready to become the leader of Egypt. It could be that Yosef understood this message and this is why he asked the chief cupbearer to remember him to Pharaoh, though of course, he might have asked him anyway.
The second distinct element of the chief cupbearer's dream is that his dream records the dreamer (the chief cupbearer) being active that the chief cupbearer took the grapes, pressed them, and put them in Pharaoh’s cup. (I thank Aaron Israel for pointing out this distinction to me.) The significance of this action is that the first dream is more essential than the second dream in the set of dreams, and in this case, it is essential that the chief cupbearer returns to his work, and recommends Yosef to Pharaoh.
40:12,13 then record that Yosef interpreted the chief cupbearer's dream that the chief cupbearer would return to his previous position with the king. Afterwards, 40:14,15 record that Yosef asked the chief cupbearer to speak on his behalf to Pharaoh. Evidently, Yosef thought that the chief cupbearer would be able to help him get out prison. The Ralbag (seventh benefit at the end of parashat Va-yeshev), writes that from Yosef’s behavior we learn that a person should not rely on miracles, but must make every possible effort to help one’s self. Accordingly, the Ralbag views Yosef’s behavior very positively. (I thank Adam Klein for pointing out this source to me.) In fact, Yosef repeats this same action, when after interpreting Pharaoh’s dream, he added on that Pharaoh should appoint a person (i.e., himself) to save Egypt, 41:33-36,
However, Chazal view Yosef's request very negatively. The Midrash (Bereshit Rabbah 89:2,3, also see 88:7, quoted in Rashi on 40:23) writes that Yosef had to spend an extra two years in prison because he twice asked the chief cupbearer for help instead of relying on G-d. This Midrash has led to a whole discussion about the proper amount of effort in this world, (see Nachshoni, 1987, pp. 160-164) but did Yosef really sin?
I doubt that Yosef sinned by asking the chief cupbearer for help since Yosef was eventually saved by the chief cupbearer. If Yosef acted inappropriately, then he should have been saved in a different manner. For example, Potifar could have mentioned Yosef to Pharaoh. Furthermore, in total, thirteen years passed from the time that Yosef was sold to Egypt to when he became head of Egypt (37:2, 41:36), is there any reason to think that just the jail time should have been shortened?
Presumably, according to the Midrash, Pharaoh was really supposed to have had his dreams immediately after the chief cupbearer returned to his position. Yet, if Pharaoh had his dreams immediately after the chief cupbearer left prison, maybe the cupbearer would not have mentioned Yosef at that time since telling Pharaoh of Yosef meant reminding Pharaoh of his sins and he would not have wanted to remind Pharaoh about his previous sins so quickly after he was released from prison. There needed to be some time to pass to give the chief cupbearer the gumption to mention Yosef's skills, and hence Pharaoh's dream had to occur after the chief cupbearer deemed it safe to recall his previous time in prison. Thus, while Yosef might have hoped that the chief cupbearer would immediately remember him to Pharaoh, more likely his real hope was that in the future, the chief cupbearer would recall his skills, which is what happened.
Robert Sacks (1990, p. 351) notes that when Yosef asked the chief cupbearer to remember him, Yosef said “when it goes well with you,” 40:14. This phrase does not refer to when the chief cupbearer would be restored to his position. Instead, Yosef requested the chief cupbearer to remember him when the right opportunity would arise (also see Siftei Chachamim on 40:14). According to this, Yosef was trusting in G-d that G-d would arraign for an opportunity for the chief cupbearer to remember Yosef, which is what occurred by the dreams of Pharaoh.
40:16,17 then records the dream of the chief baker and 40:18,19 records Yosef's interpretation of this dream. Is this second dream necessary to the story as the chief baker dies without telling anybody about Yosef?
The answer is that both the chief cupbearer and the chief baker had to have dreams in order that Yosef could have both a “good” interpretation that the dreamer went free from prison, and a “bad” interpretation that the dreamer died. The importance of Yosef’s interpretation of the dreams was that the person who went free would help Yosef get out of prison in recognition of Yosef’s help and/ or abilities. Accordingly, one person had to go free from prison. Yet, if there had been only one dream, Yosef would have had to give a “good” interpretation since a “bad” interpretation would have been useless even if correct because the person would have died without being able to tell people of Yosef’s abilities. One might answer that even with one dream, the timing of the dream, three days, showed Yosef’s abilities, but if it was well known that Pharaoh was going to have his celebration in three days, then this would have been an opportune time to either pardon or punish criminals. This means that one “good” interpretation would not have demonstrated Yosef’s abilities. Thus, there was a need for another dream with a "bad" outcome. With one “good” interpretation of the chief cupbearer's dream and one “bad” interpretation of the chief baker's dream, then the chief cupbearer would have known that Yosef could interpret dreams.
We see the need for the dream of the chief baker that when the chief cupbearer told Pharaoh of Yosef, he mentioned both that Yosef correctly interpreted his dream, and that Yosef correctly interpreted the dream of the chief baker, 41:9-13.
40:20-22 then records that Yosef's interpretations came true and 40:23 ends chapter 40 by recording that when the chief cupbearer was restored to his previous post, he forgot Yosef (lo zachar) and that he forgot him (va-yishchachehu). This verse repeats that the cupbearer forgot Yosef. Sarna (1989, p. 280) writes that the double language "is purely idiomatic and means complete forgetfulness." Yet, from 41:9-13, we see that the chief cupbearer did not forget Yosef as he mentioned Yosef to Pharaoh.
I think the word zachor in the Torah should be understood to mean to act upon some memory, and then the first forgetting in 40:23 means that initially when the chief cupbearer left prison he did not mention Yosef to Pharaoh (see Rashi and the Rashbam on 40:23), which was to be expected since then he would have had to re-call his stay in prison and possible crime. The second forgetting was that he did not tell anybody, his wife, his family, about Yosef in order to help him forget Yosef, but he never really forgot about Yosef. Accordingly, when he saw that it was to his advantage to mention Yosef to Pharaoh, 41:9 records that he remembered (zachor) his sins, which means that he decided to act upon his memory of Yosef. This action by the chief cupbearer brought Yosef to Pharaoh's notice and chapter 40 is then crucial to explain the rise of Yosef.
Bibliography:
Nachshoni, Yehuda, 1987, Notes on the parshot of the Torah, Tel Aviv: Sifrati.
Sacks, Robert, 1990, A commentary on the book of Genesis, Lewiston, New York: The Edwin Mellen Press.
Sarna, Nahum (1923-2005), 1989, The JPS Torah Commentary: Genesis, Philadelphia: The Jewish Publication Society.