Andalucía (and to a somewhat lesser extent Madrid/Toledo) is likely to be brutally hot at the time of your visit. I'd definitely stay north, and--in contravention of the usual suggestion to put your flight-departure point at the end of your itinerary--I'd be inclined to do my sightseeing around Mardrid at the beginning of the trip. The weather odds are better in June than in July. This has the advantage of eliminating the risk of missing your onward flight to Lisbon, which unfortunately is going to be a on separate ticket, so all the financial risk is yours. I wouldn't want to have to buy five new tickets at the last-minute, walk-up fare.
In addition to Toledo (my favorite smaller Spanish city), I also recommend Segovia. I do not have children and am not a good person to speculate about what might interest yours, but that aqueduct is a knock-out, and the architecture in Segovia is different from what you'll see in Madrid and Toledo. There are other sights in the city as well.
There's much to see in and around Barcelona, which unfortunately can also be somewhat unpleasant in the summer if the humidity is high. (It will not, however, have the over-100F temperatures of Andalucía.) If you enjoy hiking/walking, a day-trip to Montserrat will probably afford some cooler weather. And there are some attractive beaches not too far away. I love Girona, which has a large medieval core with a walkable wall and a number of historic sights. Note that many of the top sights in Barcelona are so popular that you must buy tickets (usually timed tickets) in advance, so you'll need to figure out what key sights are important to you and return here so we can tell you which ones need to be pre-purchased.
Up in the Basque Country, I'm one of the people who prefers the much less touristy Bilbao to San Sebastian. The latter's entire (small) historic district seems to be given over to tapas bars. Both cities are worth visiting, however. The third Basque regional capital of Vitoria-Gasteiz is also interesting. Its large historic district sits on a hill with outdoor escalators available to take the sting out of the climb. The good-sized coastal town of Handarribia, practically on the French border, is also worthwhile. It has a fishermen's district (restaurants are there) and an older medieval district on a hill (no escalators). There are also several nice small costal towns, former fishing villages that are now touristy: Zumaia, Getaria and Zarautz near San Sebastian; Lekeitio between SS and Bilbao; and Bermeo near Bilbao. The Basque countryside is very pretty. I visited all the places I have mentioned by public transportation (buses often needed) except for Lekeitio.
Edited to add: The fastest way to travel between Bilbao and San Sebastian is definitely by bus. But the local railway line provides views of some very, very nice scenery, so it's worth going that way if you can spare the time. The bus, however, is very comfortable. Arguably more comfortable than that particular train, which I recall as having plastic seats of the type you might find on a subway car.
I haven't been to Portugal recently, but I know that you should not try to see Porto while staying in Lisbon, or vice versa. You'll need (at least) two bases in Portugal if you want to see Porto. Traveling from Barcelona to Portugal just to see Lisbon would chew up quite a lot of time for the flights back and forth. I'd tend to want to see more of the country if I were going to go there. But Spain (even just the part north of Madrid) is a very large place with many interesting potential destinations, so it's a trade-off.