I'd be tempted to drop the Costa del Sol (much of which is a ticky-tacky mishmash of English pubs and German sausage joints) and get my beach fix in Barcelona. However, traveling with kids may dictate more than one beach break. My next choice from trimming 3 days would start with dropping Coimbra, which is interesting but not a blockbuster like your other destinations (except Costa del Sol). But you say you're locked in to the Portuguese stops. I would recommend that you not book any more non-cancelable lodgings, because there remains a possibility you won't be able to make the trip.
If you really do have to drop 3 days, I guess I'd cut Barcelona. I love it, but it's a geographical outlier. Maybe you'll have a chance to see it on a later trip (maybe to France?). On the other hand, there may well be more to interest the kids in Barcelona than in some of your other destinations (like Porto).
Your 1 day in Granada probably means 1 night, and that will amount to less than a full day unless you take an early train from Madrid and a lateish train to Cordoba (which cuts Cordoba short, since you only have 1 night scheduled there, too). That will mean a rushed visit to Granada, where the Alhambra alone can soak up considerably more than half a day. If your kids won't tolerate more than a couple of hours or so at a sight like that, perhaps it won't matter so much.
Although there's nothing wrong with the order of your itinerary, assuming you've identified flights from Porto to Madrid (ground transportation doesn't work well for that leg), you have some flexibility about where you slot in Cordoba. As the train lines are laid out, you're likely to pass through Cordoba on the way from Madrid to Seville, from Madrid to Granada, or from Seville to Granada. So do what works for you in terms of being in the various cities when you want to be (weekdays/weekends, etc.) and getting trains at convenient times. There's not a lot of service in and out of Granada, I'd recommend researching those options first.
If you're planning to drive instead of using public transportation, use ViaMichelin.com to get an idea of driving times. For your Spanish destinations, driving will probably be a lot slower than the AVE trains. I don't know about Portugal.
You'd save a good chunk of a day by flying home from Spain (might need to be Barcelona or Madrid from a financial standpoint) if your airline tickets are changeable. As it stands, you're going to have to give up most of the last day of your trip to get back to Lisbon (the entire last day if you're driving, of course).
By the time you get to Spain, it's likely to be quite hot there, though probably more moderate in Barcelona. You may find you need mid-day breaks in an air-conditioned hotel room. I use booking.com to search for rooms. The reviews are all from people who've actually stayed in the hotels, and I find them generally reliable and helpful.
If you're looking for specific hotel recommendations, you need to tell us your nightly hotel budget in euros and the ages of your children (since one or more might count as adults). I assume there are 3 children. I think you're going to have a hard time finding rooms for five. Apartments (about which I know nothing, really) may work better.