The best time to visit Madrid for pleasant weather is during the spring (April to June) and fall (September to October) when temperatures are mild, and outdoor activities are enjoyable.