Without getting into Egypt's current economic crisis, suffice it to say the country has a number of capital controls that aim to limit outflows of Egyptian currency. In October, the government instructed local banks to restrict the use of Egyptian Pound debit and credit cards outside the country and imposed limits on the amount of foreign currency Egyptian bank accountholders can withdraw. Foreign currency for imports is apparently subject to prioritization for "essential" goods.
As a result, the "official" exchange rate doesn't represent the true price people are willing to pay for Euros. If people could get all the Euros they wanted from their local bank at something like 1 to 33 (and if their local bank could get all the Euros it wanted from the central bank), they'd gladly do so, but they can't because of the capital controls. So people who still want more foreign currency are willing/forced to pay a higher price for it because the supply is limited. You, since the Euros in your wallet you flew in with aren't subject to the same restrictions, are offering some of that supply and so benefit from the higher price.
I can't speak to the legality of these parallel market exchange transactions in Egypt.