The best time to visit Morocco is in the spring or in the fall as the weather is more pleasant than warm summer time. Usually, the months of March and April are good times to visit, otherwise, the months of September and October are good times too. The rainy season tends to be during the winter months, sometimes during November. In the summer, the weather is very hot, especially in the south of Morocco and in the desert. There is air-conditioning in the hotels and even in some Sahara camps, but please be sure you have the right expectations if you are looking at visiting Morocco in July or August (the hottest months).
Note: You will have a different experience in Morocco if you come during Ramadan, the holy month of fasting for Muslims. During this month, Muslims fast from sun-up to sun-down. It will affect your tour in the following ways: there will be fewer options for restaurants during the day time, alcohol will not be available in your hotel or in restaurants, and the mornings will be much quieter as the community wakes up late. In 2020, it will go from the end of April to the end of May.