So this might be bordering on the ASB: what if shortly after the death of his son, Felipe IV decides, rather than remarrying, to legitimize D. Juan José and marry her to Maria Anna of Austria instead of marrying her himself. He was, by all accounts, quite attached to Élisabeth de France and despite her dying in 1644, only remarried in 1649 – after his son had died. Spain and Portugal have both had bastard sovereigns before – so it’s unlikely that anybody in Spain proper (except maybe the other bastards of Felipe IV) will kick up a fuss; France might, but their claim to the Spanish throne is weak – via Felipe’s sister who renounced her rights – while Felipe still has a legitimate daughter and a legitimized son; Austria might, but Felipe can maybe mollify them by marrying Maria Teresa off to the King of the Romans if he has to. Maria Anna herself might bitch – maybe, she didn’t like JJ OTL, but IIRC that was because he was a threat to her son’s rights – but if her father and uncle say so, she’s going to the altar with Juan.
Now, as to Juan himself, he was clearly his dad’s favourite. He screwed up a couple times – served as viceroy in Naples, in Catalonia and in the Netherlands – although Maria Anna undermined him when he wasn’t in Madrid. Many at court hoped for great things when he seized power in a coup from Maria Anna, but ended up being sorely disappointed. On his death bed, Felipe suggested that he marry a Mazarinette, but he took it into his head to rather marry his half-sister, Margarita (they’re Habsburgs okay, that’s how they roll), instead. So clearly he had the ambition to be king, IMHO I think he was just to worn out by the time he actually got there, and just said ‘laissez le bon temps roulez’, so if he gets there earlier he could be a half-decent ruler – certainly better than Carlos II (read: Maria Anna).
How might the future of Spain be affected by a marriage between Juan and Maria Anna (probably a few healthy kids, at least)? And more importantly, by Spain getting Juan III in 1665 rather than a bewitched king who had everything wrong and yet defied the odds for 39 years?