The curse of the seed of Cain was that they would not be able to hold the Priesthood. Cain’s seed was preserved through the great flood because Ham married Egyptus (Abr. 1:21-27). Joseph was later sold into Egypt by his brothers. Pharaoh gave him Asenath to marry, daughter of the priest Potipherah. Since the Hebrews were not yet captive to Egypt, it has to be assumed that there were few there and that Pharaoh gave Joseph an Egyptian to wife. Asenath is the mother of Ephraim and Manassah. They therefore would be partially through the lineage of Cain. Ephraim and Manassah were not denied the priesthood as evidenced by the fact that Lehi was a prophet and along with Nephi and other sons brought the priesthood with them to the “promised land” as documented in the Book of Mormon. If they were seed of Cain how was this possible?
Your question contains two misconceptions: 1) why Pharaoh did not hold the priesthood, and 2) Egyptian demographics at the time of Joseph.
Cain’s curse for murdering Abel was that the earth would no longer produce for him (remember he was a gardner), and he was shut out of the Lord’s presence (Moses 5:36-37,40).
And now thou shalt be cursed from the earth which hath opened her mouth to receive thy brother’s blood from thy hand. When thou tillest the ground it shall not henceforth yield unto thee her strength. A fugitive and a vagabond shalt thou be in the earth.
And Cain was shut out from the presence of the Lord, and with his wife and many of his brethren dwelt in the land of Nod, on the east of Eden.
Cain’s curse for following Satan (by offering a sacrifice of grain) was the he would be known as the first conspirator in the history of secret combinations, he would be known for following Satan, and his soul would be lost (perdition) (Moses 5:24-25).
For from this time forth thou shalt be the father of his lies; thou shalt be called Perdition; for thou wast also before the world. And it shall be said in time to come—That these abominations were had from Cain; for he rejected the greater counsel which was had from God; and this is a cursing which I will put upon thee, except thou repent.
There is no mention of priesthood and Cain in the scriptures.
You are correct that Pharaoh did not hold the priesthood based on his lineage (Abr 1:27).We don’t know how long such a proscription lasted; we don’t know if it was still in place two generations later when Joseph returned to Egypt.
Now the real answer to your question is understanding who was in Egypt at the same time as Joseph. During the Second Intermediate Period (between the Middle and New Kingdoms) Egypt was under the rule of the Hyksos – a group of foreign, Semitic shepherd-kings. Joseph then probably married someone of Canaanite origin.