This is a good time of the year to visit Madrid, especially to enjoy the long warm nights in June, when the street life is at its best. The real problem with this time of the year in Madrid is that it doesn't cool down very much at night, making sleeping uncomfortable for those without air-conditioning. An important summer phenomenon is that in August the locals pour out of the city en-masse. If you like to have 'the city to yourself', then August may be the time for you to visit. If you're lucky, the cooler weather will return sooner rather than later.
Rain is infrequent but there are the occasional summer storms.
Sandals are a very good idea, and Madrid is a good place to buy them. Sun cream if you are of fair complexion. Like spring, autumn is an excellent time for a visit. The city's mood is quite different as everyone has recently returned to work or school after the August holidays, the temperature is very pleasant with people relieved that the intense July sun is behind them. There are also plently of cultural activities going on.