Who were the Medanim?
Rashi (to Bamidbar 31:6): The Medanim are synonymous with the Midyanim. 1 Malbim - they pulled Yosef from the pit and sold him to the Yishma'elim, and caused that he be sold to Egypt.
Rashbam: Medan, Midyan and Yishma'el were (paternal) brothers. 2 According to the simple meaning, Medan and Yishma'el were one and the same, which is why it says below (Bereishis 39:1) that the Yishma'elim brought him to Egypt and sold him there.
Bechor Shor (to 37:28): Medan, Midyan and Yishma'el are all the same, 3 just like Yehudim, Ivrim, Yisraelim and Yeshurun all refer to the same nation. The name is based on what they were carrying.
This explains why Pinchas went to fight against Midyan - to avenge the sale of his maternal ancestor, Yosef, whom they sold to Egypt. (Medan and Midyanim were different sons of Keturah (Bereishis 25:2)! Perhaps he holds that Medanim are not a different nation because the Torah did not list any sons of Medan - PF.)
See Bereishis 25:2.
Riva: They are called Yishma'elim since they lived in Yishma'el's land.
If this verse tells us that the Medanim sold Yosef to Mitzrayim, why does verse 39:1 say that it was the Yishma'elim?
Gur Aryeh (to 37:28): Refer to 37:28:1.01:2, 37:28:1.01:3, and 37:28:1.03:2.
Why does the Pasuk refer to Potifar as "Seris Pharaoh"?
Ramban and Targum Yonasan #2: Refer to 39:1:2:2.
Gur Aryeh (to 39:6): It does not mean castration; we will learn that Potifar did have relations with his wife (Rashi to 39:6,19). Rather, it means servant or official, as Targum translates.
What exactly was Potifar's position?
Rashi: Chief slaughterer of Pharaoh's animals. 1
Hadar Zekenim, Moshav Zekenim (Bereishis 39:1), Targum Onkelos and Targum Yonasan: Chief executioner. 2
Rashbam (to 39:1): Chief judge - to pass the death-sentence over those who were incarcerated in the royal prison.
Ha'amek Davar: The custom was, if one came to sell a slave, and it is hard to wait until he finds a buyer, the country bought him and stood him up in the market until he was sold. Potifar was appointed over this. 3
Hadar Zekenim rejects this, for it is To'evah to Egypt (their deity). Riva and Tosfos ha'Shalem (39:1:9) citing Moshav Zekenim say that they despised only "Ro'ei Tzon" (46:34); they worshipped only Tzon, but ate cattle. Some say that they worshipped Tzon only in Nisan, for its Mazal is a lamb. Moshav Zekenim brings Moshe's words during Makas Arov, "if we would be Zove'ach To'avas Mitzrayim in front of them, would they not stone us?!" (Shemos 8:22). This was not in Nisan, for there was a month between plagues! Perhaps he meant, 'We cannot sacrifice it even now, for they worship it in Nisan [even though in other months, also they slaughter and eat it].' This requires investigation (PF).
The Ramban too, prefers this explanation, even though we find the word "Tabach" in Tanach in connection with both meanings. Refer also to Bereishis 39:1.
Refer to 39:1:152:1.
Why does it say that they sold Yosef "to Egypt"?
Gur Aryeh (to 37:28): According to an opinion in the Midrash, upon Yosef's arrival in Mitzrayim, the Medanim sold him to "Mitzrayim," i.e. to the public official 1 over that region of Egypt -- who then sold him to Potifar.
Ha'amek Davar: Potifar himself was the Egyptian official in charge of facilitating the sale of slaves. 2 Refer to 37:36:3:4.
Maharal (Gevuros Hashem Ch. 11, p. 63) - A slave to the public is not completely a slave, for sometimes even a nobleman will work on behalf of the public. Only afterwards was Yosef sold to a private individual, becoming a slave in the full sense of the word.
Nevertheless, Potifar eventually managed to purchase Yosef for himself. Refer to 39:1:152:1.
QUESTIONS ON RASHI
Rashi writes: "'Sar ha'Tabachim' - [I.e. the officer in charge of] slaughter of the king's livestock." Targum, however, translates as "chief executioner." What are they disputing?
Gur Aryeh: According to Rashi, Hashem surely would not deliver Yosef into hands tainted by human blood. 1 Targum Onkelos, on the other hand, is consistent with the meaning of the term Sar Tabachim in Daniel 2:14. But in this case, Potifar would not do executions himself; he would oversee others who did the dirty work (as such, it was not disgraceful that Yosef be in his hands).
Gur Aryeh: We see that Hashem even spared Yosef the unpleasant environment of a foul-smelling Yishmaelite caravan, sending him with fragrances instead; surely He would not place Yosef in the home of a murderer!