The short answer
Under about four, usually yes: the long drive, daytime heat, cold nights and basic sanitation at budget camps turn it into a slog. From about five or six, a Sahara night at Merzouga is often the highlight of the trip, if you split the drive over two days each way and book a camp with real beds and bathrooms.
In more detail
The distance is the problem, not the desert. Merzouga and the dunes of Erg Chebbi are about 560 km and 8 hours 30 minutes of driving from Marrakech over the Atlas. With children, we break that over two days each way, with a night in Ouarzazate or the Dades, so no one spends a whole day in the car.
Once you are there, the desert is kind to children. The camel ride into Erg Chebbi runs about 20 to 40 minutes from the road's edge to camp, within reach of a child of about five, and guides seat young children in front of a parent. Comfortable camps have proper beds and ensuite bathrooms, and for families the gap between a budget camp and a good one is enormous.
Pack for cold. Desert nights run about 10 to 15°C in spring and autumn and drop to about 2 to 5°C in winter. Avoid July and August with young children because of the heat.
If the drive is too much this time, an overnight at an Agafay camp, about 40 minutes from the city, gives the camel, the open desert and the campfire without the long road. Save the dunes for when they will remember them.
