Because the Pope said so.
Because Philip had three rebellions at the same time, and he didn’t have the forces to quell them all, so he kept the Netherlands and Cataluña and let Portugal go.
Because he was too German for his own good.
So wanted to retain the Hapsburg possessions in the Netherlands.
But that ultimately failed, or Cerb would be speaking Spanish rather better than he does now. That or he would roll his r’s like the next Flem.
During the Roman times, Spain was Iberia, and there was not really a distinction between what we now call Spain and what we now call Portugal.
But then the Empire fell.
Only the Church remained.
Then the Germans invaded Iberia/Spain, and many little kingdoms sprang up, mostly around bishoprics at some level. But then that Moslem Prophet started his big dealio, and everything fell.
Asturias at the very top was never conquered, and the top of what we now call Galicia. Plus Charlemagne stopped the Moor at Roncevalles, or so the legends tell us.
So for seven centuries, Spain was recovered slowly, like a window-shade rolling down from the top.
For a while there was a Caliphate in Córdoba.
Then there were many little taifa states.
A mixed feudal system developed, and sometime the same baron would fight this war for a Christian king and that war for a Moorish one.
Portugal, which had been Lusitania and Gallaecia under the Romans, became a county.
The Count of Portugal owed fealty to the King of León.
Note that León is named not for a lion but derives from the Roman legion stationed there.