I live in Morocco, and I just went to the gendarmerie to ask this very question.
Officially, it is illegal to camp in the wild in Morocco. Camping is only allowed in registered campgrounds. People do it, and foreigners usually are tolerated, but the gendarmes worry about the security of those who do this.
Thought you should know.