Upvote:3
You'll need a visa only if you want to leave the airport.
National Egypt (EG) /Transit Morocco (MA) Destination Egypt (EG)
Visa required, except for Children under 17 years of age of any nationality , if having Moroccan parent(s) and being registered in parent's passport
TWOV (Transit Without Visa): ... Visa required, except for Holders of confirmed onward tickets for a max. transit time of 24 hours at Casablanca (CMN)
Since your layover is under 24 hours, you can transit without a visa if you stay in the airport, but you'll need a visa if you want to enter Morocco.
Source: Timatic