Blaming foreigners is the trick local politicians love to use, but - at least in Portugal - very few properties are foreign-owned. Instead, people are reluctant to rent properties out in general. Real estate agents struggle to convince owners to put their properties on the market in a first place. Usually a family member dies or moves abroad and their relatives simply keep the place unoccupied. Often to convince them to rent out you have to play a match-making game: you have to know both lenders and prospective tenants for years and be a guarantor of their good character. The more contacts the two parties have in common the better. Portuguese society is very socially conservative, often connections matter a lot more than money, and rent market is one area of the economy where it is very noticeable.
To sidestep the whole "can we trust each other?" issue the owners may want to sell the property instead of dealing with tenants. Properties go to the market at inflated prices, because every house owner in the country hopes to sell to mythical "rich foreigners"* they hear so much on TV and online. Local buyers are essentially priced out of the market because the price-wage gap is simply too wide, one of the widest in the world. An average Portuguese family with two incomes can't afford a two-bedroom apartment even at a 30-year mortgage, even if we're talking about cities other than Lisbon or Porto.
So, properties stay listed for sale for years and years, owners do not maintain them in hopes of making a sale "soon", and buildings slowly degrade. Eventually owners realize they need to invest a lot of money to keep the house presentable, the money they usually don't have, and they start to lower the price way down. As a result, the market is split in two big distinct categories: something livable at exorbitant prices and places that need a lot of investment to even start living there. Like a GP comment said you can walk on a street and more than half of places are clearly unoccupied, with many of them slowly turning into ruins. If you want to describe a Portuguese urban landscape in one word the word would be "decay".
Meanwhile rent marked is under-served. All this is further worsened by the internal migration pressure. Lisbon, Porto and all towns on a narrow shore strip between the two are growing rapidly in past 30 years while the interior areas are getting deserted. Portuguese move to places where jobs are and developers can't meet the evergrowing demand.
*I recall I saw a stat that foreigner buyers account for only about 0.2% of sales each year.