"They offended" [the cupbearer], and so forth (Genesis 40:1). The chief cupbearer — a fly was found in his lukewarm drink; and the chief baker — a pebble was found inside his fine loaf. Another interpretation of "they offended": they sought to couple with the daughter of the king. It is said here "they offended," and it is said elsewhere, "How then can I do this great wickedness, [and sin against God]" (Genesis 39:9).
Why Pharaoh's Cupbearer and Baker Sinned Against Their Lord
Midrash Aggadah, Genesis 40:1
חטאו משקה וגו'. שר המשקים נמצא זבוב בפושרין שלו, ושר האופים נמצא צרור בתוך גלוסקין שלו: ד"א חטאו. בקשו להזדווג בבתו של מלך, נאמר כאן חטאו, ונאמר להלן ואיך אעשה הרעה וגו' [וחטאת לאלהים]: