Many countries do prohibit the import of cash in the mail.
From the Royal Mail website:
Currently, the following countries all prohibit the sending of cash:
Armenia, Australia, Belarus, Bolivia, Botswana, Bulgaria, Cape Verde, Central African Republic, China (excluding Hong Kong and Macao), Comoros, Cuba, Czech Republic, Dominican Republic, Georgia, Hungary, India, Iran, Iraq, Kazakhstan, Laos (People�s Democratic Republic of), Latvia, Lebanon, Lithuania, Malawi, Montenegro, Namibia, New Zealand, Nicaragua, Norway, Oman, Pakistan, Poland, Rwanda, Serbia, Saudi Arabia, Swaziland, Tajikistan, Uganda, Uzbekistan, Yemen, Zambia, Zimbabwe.
Egypt is not listed, so ought to have been OK, though I guess things change from time to time.
There are other countries that only allow cash in registered mail - maybe Egypt is one of them. I can't find a list
As to how they knew - if it was a small package then customs probably opened it, as they are entitled to.