Summer months is the time when Madrid gets flooded with tourists. Many Spaniards have vacations and come to visit the capital in large numbers. Also, there are many school and college students visiting local museums and landmarks. Hotel prices are usually higher and lines to places like Prado Museum and Royal Palace are much longer.
At the same time, many residents of Madrid are also taking vacations and therefore some restaurants, shops and art galleries might be closed. It's worth to add that July and August are the hottest and the driest months in Madrid so sightseeing outdoors is only possible early in the morning and in the evening.
For these reasons summer is not the best time to visit the Spanish capital even though it's a rainless and sunny time.