Non-Historian here, but Portuguese that likes history.
One major problem the Portuguese economy had during the discoveries and then the Industrial revolution was the dependence of the State (King). There weren't many Portuguese rich-man that were available to invest in the new business, and later the investments were made with the help of the State. For example, the discoveries in Portugal were sponsored by the State and I think in England and the Netherlands, there was a company for that (The Easter Indies Company or similar).
Portugal was also a catholic devote country and in many regions you still find people averse to innovation. If things were running well enough, there was no need for inventing. This is something cultural, and you can still notice the differences between the Portuguese and other European countries population.
Portuguese colonies offered good resources for Portuguese elite, if you had the money in Portugal you could just invest in guaranteed investments with good return in the colonies, such as S. Tomé e Principe, Angola, Moçambique.
Portuguese market was also an obstacle, contrary to big countries as France and the UK, Portugal had a population of 3 million in 1800, England had almost 8. However if you notice the difference on the capital, Lisbon had 200k and London had almost a million.
Additional to these obstacles we also had other problems during the years of the industrial revolution. *French invasions during Napoleon reign (1807) that lead to a flee of the court to Brazil. *Brazil independence in 1820, it was our richest colony and different from the US. *Relation with England, with many business in Oporto (Portuguese second biggest city) being owned by Englishman.
I also remember that the first Portuguese coal electricity producer was dependent on the English, our coal was of inferior quality so we had to import.
Sorry I can't help about Spain.
Answer in one word? War. Continual war since the mid 16th century that consumed the country's resources and left the people in poverty until the 1960's. Even today, the Spanish economy is still suffering the effects of a prolonged war state.
"Really?" you ask. "War, war and more war?" Yes.
It all starts at the height of the Spanish empire. Carlos V (and later his son, Felipe II) were Kings and emperors over a vast empire that extended across Europe, over huge swaths of land in North and South America, and also the Philippines. At that time (~1555) the Portuguese throne was also part of the Spanish empire, and since the Portuguese had holdings along practically every coastline from Brazil to the Philippines, the Spanish empire had holdings that were at least as considerable as that of the British Empire years later. The trouble? The Spanish empire was under siege from a variety of fronts:
So, fighting off the French in the west, the Turks in the south and southeast, and the protestants in the east and north, the empire was under considerable strain from fighting essentially three wars at once and was borrowing money like crazy to fund all these campaigns. When Felipe II took over from his father, he found some success against the Moors, but ultimately was unable to resolve the other conflicts quite as well.
Then the English, deciding they were no longer catholic, went and killed their "Catholic princess" and possible heir to the throne, Mary, Queen of Scots. Once again, Catholic Spain came to the rescue by declaring war and assembling the infamous, "Invincible" Spanish armada. The English did some cutesy things with fire ships, and as the armada roiled around trying to avoid them, they got scattered, just as a massive storm hit and decimated the fleet. Protestants hailed this as a great victory, where they really just got lucky, but the result was the same: Spain again lost a lot of power and money.
Felipe's son, Felipe III, inherited an altogether-not-too-great situation, and unfortunately for Spain, was not capable of it. He was a weak, unispiring king and he spent money partying while the empire fell apart. Felipe IV did little better, and his son, Carlos II, was completely medically incapable of ruling. Court intrigues, increasingly spurred on by foreign powers, ignored the throne almost entirely by this point, and the only thing that Carlos II of any importance was to name a French prince as his successor, and since the rest of Europe felt threatened by a potential French - Spanish alliance, this was contested and led to the Spanish War of Succession, which further decimated the Spanish treasury and holdings.
This pattern continues with:
Spain is completely knocked off the bucket at this point, and has been decimated as an empire, losing most of its European holdings.
Then the american colonies start declaring independence in 1821, and Spain loses all but Cuba and Puerto Rico by 1832.
Then there's a series of three Carlist wars from 1832 to 1876. These were civil wars, fought between factions within Spain, to decide who should take the throne.
They decide finally to ask an italian prince if he'll rule for them, but Amadeus of Savoy doesn't really want to rule, and abdicates in 1873. So they try a republic instead of a monarchy. That lasts even less time, and they go back to having a king, Alfonso XII, who fights off rebels in Cuba, which causes the people to breathe a sigh of relief at having retained at least a little of of their colonial holdings. In their minds, they still have at least a small piece of something to call "an empire".
Then in 1898 the Spanish-American war starts due to trigger-happy America and their Manifest destiny; they lose Puerto Rico and Cuba here and with it any idea of being an empire. Until this point there was a lot of popular denial of the bad things that had happened in the country; the Spanish people clung to their memories of better times and a hope of becoming great again, but this was the final straw in the national psyche, and the people became completely disillusioned with their gov't, and depressed with their current state.
I should point out here that in the Basque and Catalan regions of Spain that there were some inklings of industrialization during this mid to late 18th century period. Barcelona and Madrid had some factorization occur as well, so they weren't completely un-industrial. Spain proper though had always been very agriculturally based, and this coupled with their poverty due to their continued wars left them without much industrial impulse.
The 20th century went down like you might expect, with a lot of war. Besides the first and second World Wars, the Spanish had their civil war in the late 30s, which was a result of more unstable rule (I'm paraphrazing a lot; their civil war was really, really terrible. EDIT: maybe check out /u/tobbinator's comments on the subject for more info). They tried a republic again in the early 30s, but that didn't work any better than the first time.
Ultimately, Francisco Franco, a fascist dictator, ruled from 1938 to 1975. While he helped reestablish Spanish national pride by hearkening back to imperial days, he also did some very terrible things, and he did have totalitarian control, which restricted personal freedoms. In the later years of Franco, Spain finally hit its industrial revolution, and caught up in a lot of ways with the rest of Europe and the West.
So there you have at least 18 major conflicts and wars since 1555, and I doubt that's completely accurate; that's just what I informally counted here. That's pretty bad. These weren't "oh, let's go save Iraq/Afghanistan from evil rulers (and secure our standings and oil in the Middle East while we're at it)" wars where the nation is relatively left out of it. These were wars where Spanish soil is involved and an incredible amount of national GDP is being spent almost every time. You can't go through that and not suffer an incredible setback.
Honestly, Spain's history after the death of Franco is fairly incredible - Juan Carlos I does a lot of fairly unselfish things for the country, and they are finally able to give the people more freedoms, even minorities. He's kinda a hero of mine, even though I'm not Spanish myself. Spain is still divided in a lot of ways and smarting from centuries of war and political turmoil, but their situation today is loads improved, and is really remarkable if you know a bit of their history. If you have time and are interested, check it out!
This is something we discussed in my military history class briefly but it was during the 17th century and after that Spain and Portugal really began to fall behind despite massive amounts of windfall wealth coming in from their colonies.
Firstly there was a slight population crisis as large numbers of men left Europe for the colonies or were killed in warfare.
secondly Wars took a huge toll on the economy. Unlike the system of long term, low interest loans developed by the dutch, then later the enlgish parliament (which allowed them to raise huge amounts of money for war and pay it back slowly over time- see "the sinews of power" by brewer) the spanish were only able to borrow short term high interest payments and this left the government straddled with ever increasing debt.
as the others said, money was the issue