Although you might get lucky, you should assume the temperature will be up in the 90s while you're in Andalucía; it could be worse. Madrid is hot in the summer, too, just not quite that bad.
Weather aside, I'd encourage you to spend the maximum amount of time in Andalucía given that you're flying into Seville. It will be easier to return to Madrid on a later trip and see that city, Toledo, Segovia, etc.
Is your flight home on Friday? If so, I'd do something like this:
Friday: Fly into Seville (4 nights);
Sat-Sun-Mon: Seville with day-trip to Cordoba
Tue: Travel to Granada (2 nights)
Thu: Travel to Madrid (1 night)
As it happens, all the fast trains from Seville to Granada go through Cordoba; sometimes you even have to change trains there. That means you have two additional options that would somewhat reduce the amount of time you spend on trains:
- See Cordoba in transit to Granada, checking your luggage at the Cordoba bus station.
- Spend 3 nights rather than 4 in Seville, then spend 1 night in Cordoba before you go to Granada. The advantage of this strategy is that you get to spend a night in Cordoba. On the other hand, you have to go through the hotel check-in/check-out process one extra time.