If you overstay your visa in Morocco, you cannot exit Morocco before fixing your immigration status.
To fix your immigration status, you have to clear a visa overstay fine of 1000dh and its quite a lengthy process below is more info on how to clear immigration fines.
Process of visa overstay fine payment in Morocco
Start at emergency police services( prefecture de police) to book a court appointment and also give an official statement as to why you overstayed your visa ( you'll also be given a separate appointment for statement issuing)
After issuing your official statement, you'll have to see a judge who will state the fine. ( In most cases statement issuing and court hearing are held on the same day)
Pay your fine and go back to the police to get an exit permit otherwise, you'll still not be able to exit Morocco.