Like the Roman Empire, the powerful and successful (at the time) Egyptian dynasties welcomed folks from other areas and likely even recruited some of them as soldiers, locally, when Egyptian armies fought outside of Egypt.
There were likely even alliances of convenience the Egyptian rulers made with leaders of non-Egyptian tribal groups across the Middle East.
Trade also brought in “foreigners”.
It surely did not happen at once, but gradually over time an alliance of “outsiders” settled in Egypt for quite some time thought they had been getting the short end of the stick and took over. They were probably found at the time spread all over Egyptian society, including the military.
Some Roman losses of territory of the empire happened the same way.
The Egyptians usually had a massive food surplus, which made all their side projects (big temples, pyramids, probably something like the dole) possible, and when neighboring areas didn't have their poop in a group, refugees would enter the country. Also, Egypt was intermittently an occupied territory starting with the Hyksos and continuing until, well, the present, since the Arab population is not a native one, it's just been around a long long time, look at that.
"An alliance?
"An alliance!"
"Now get out of here!"