I agree with
@henrythedog that Salamanca is a great place to visit. Zamora would be high up on that list too. Salamanca has one of the prettiest Plazas Mayores in Spain in addition to the old university, which is composd of one historical Renaissance building after the other. Several convents there are also worth visiting.
Zamora is smaller, has a castle and cathedral, and more than 20 Romanesque churches. If you are a fan of Romanesque, this would be the deal-breaker between the two, IMHO. The tiny Santiago de los Caballeros is where El Cid reportedly spent his night in prayer before being knighted. It is one of my favorite places in Spain. Both cities have a lively atmosphere, Salamanca will be more touristy, but both are great places to sit or to wander.
Salamanca and Zamora are very close, about 60 km apart on the Camino Sanabrés, so it would be easy to go Santiago - Zamora - Salamanca-Madrid, with two nights in both of the places. I don’t think that would be too rushed. Two hours on the train from Santiago to Zamora, an hour bus ride to Salamanca (much easier and quicker than train for that leg), and then a couple of hours on the train to Madrid.
The other thing I’d suggest is to take two two-day trips from Madrid, one to Segovia and one to Toledo. Both are very close, extremely easy to get to, and great places to see. Spending one night in each place will give you time to enjoy the cities at night and without the tons of day-trippers from Madrid.
Segovia has the aqueduct, the Disney-like castle, a cathedral, several Romanesque churches,and if you are a meat-eater, lots of restaurants offering the local specialty, roast suckling pig. Even if meat isn’t your thing,there is a Sefardi restaurant with lots of excellent veggie options, La Taberna del Fogón. There’s not as much to see here as in Toledo, but just seeing the aqueduct lit up at night when the tourists are gone is worth it. Lots of places to sit and just enjoy the great ambiente.
A trip to Toledo in August will mean busloads and busloads of tourists, but it is one of those “jewels”. If you go, I would highly recommend spending a night. Walking around when the tourists are gone and the city is illuminated is pretty great. I would highly recommend getting a 12€
tourist bracelet. With it you can visit 7 sites that are not on the first tier tourist trail but are so interesting - a mosque, a synagogue, a bell tower with a great view, etc. You can use the bracelet over several days, and going to these monuments really takes you through lots of out of the way parts of historical Toledo (not that much is out of the way in historical Toledo but you will see streets without a million tshirt and cheap food shops). Walking to a mirador on the other side of the river and up a hill will give you the famous El Greco view of the city. I walked into Toledo that way on the Levante and it is as beautiful a built environment view as any I’ve seen.
Lots of good options here, let us know what you decide!