saw,
You likely won't be able to see much walking around Madrid for just a few hours, but if that's important to you it's certainly possible. Given the circumstances you mentioned, I wouldn't bother booking another flight as the rides back and forth to the airport would use up some of your valuable times. In this case, travel by train would be a better option (IMO). There are direct high speed AVE trains on that route with a travel time of about 2.5 hours, which is probably going to be much faster than by air, when all is considered. The trains travel at up to 300 kmH so very quick.
After leaving the airport, you could go directly to Madrid-Puerta de Atocha station. According to THIS website there are luggage lockers there behind the Aviary. Spend a few hours looking around Madrid and then return to the station for your train to Sevilla. I'd suggest not leaving it too late, as I never find it pleasant when I arrive late in a new city. Also, with earlier travel you'll have some time to admire the scenery during daylight hours. A departure from Madrid at 19:00 is about the latest one I would take. I can't remember the stations in Sevilla, but your destination will probably be Sevilla Santa Justa. You can see all the details on the bahn.de website.
If you decide to use this method, it would probably be prudent to pre-purchase your rail tickets. However, one point to note is that they will have compulsory reservations so will be specific for one train, date and departure time. Don't be late getting back to the station after touring Madrid or the tickets will be worthless!