Why Fez and Marrakesh became the dynasties capitals and most important cities of Morocco?
Mostly from their relative central position on Maghrib (as far it was doable avoiding most of Atlas Mountains), and their good connection to both IOTL Mauritania and al-Andalus.
These cities, especially Marrakesh in the Marinid period, did went into periods of huge decline, tough.
Lucky or some natural/strategic reason?
A mix of administrative, strategical and political reasons (Marrakesh was basically restaured by Saadian, in order to make a political point).
As for natural ressources, it's less that they were required from day 1, but the presence of running waters in Fes indeed allowed the city to outgrow the others by having the capacities to do so.
For example, why Fez and not Meknes, Volubilis or Taza?
Meknes and Taza
were important cities in medieval Maghrib, and the first is considered an imperial city.
What prevented them to really challenge Fes on the long run? Mostly political reasons, as they weren't the seat of strong ruling dynasties, apart from Idrissids that made Meknes their capital.
Taza is a bit excentered admittedly, being more on the coast and a tiny bit peripherical of the western Marrocean coast, more a the entry of western Maghrib than anything.
As for Volubilis, the city had already declined by the VIIth century (a bit like other western cities) and didn't really challenged the new foundations of towns, cities, etc. that popped out in all the Maghrib. Declining and being in concurrence led to a slow disappearance (even if the place was inhabited up to the XIIth century)
What was the population of Morocco at the time (let's specify around the year 1400 A.D)?
Hard to say, but it couldn't have been that much : maybe 4 or 5 millions at best IMO, counting semi-nomadic and nomadic Berbers.
Which were the biggest cities?
Fes, Marrakech, Taza, Meknes, among others.