Foundries were an off-shoot of the DARPA MOSIS program and Japan got into semiconductors a bit too early. Much the same reason by there are few/no US foundries of note or volume as well – the momentum for already in play for vertical, captive business models and fabs.
Most fabs in Japan have been captive, vertical fabs where the same company that makes the chips also designs and sells the same chips. Basically the diametric opposite of foundries. The transition from captive to foundry is NOT trivial. It requires a cultural change in terms of control and openness of many operational aspects. As a side note: it’s unclear that Intel can make the transition from vertical captive fab to the foundry. Their efforts so far have resembled a socially inept nerd trying to ask out the prom queen – they clearly don’t “get” the culture/nuances/dance of foundry work (yet).
Japan has effectively been in a deep economic depression for 20 years now. Capital has not been there to invest. Japan played a “wait it out” strategy without forcing “too big to fail” banks and businesses out of business and into liquidation. That failed grievously. Now they are trying Quantitative Easing and things (as expected) are getting worse, not better.
Japanese Business Mentality
Dedicated fabs making well-defined hardware products like DRAM or Flash fits with Japanese business sensibilities, strengths and habits. It’s like making steel or consumer electronics. Very vertical. Very controlled. Relatively static. Making general purpose foundries where the product is defined by customers and implemented primarily in terms of software, is, to put it bluntly, anathema to the same business sensibilities, strengths, and habits. It’s like making software or internet businesses when you’ve only make hardware – it’s hard and doesn’t always work out.
Taiwan Business and National Mentality
Taiwan has a similar “island export mentality” to Japan which much of it coming from Japan itself (Taiwan used to be a Japanese colony). But Taiwan is also Chinese, who culturally have a more open and free-wheeling business sensibility than Japan. Korean is similar BTW, hence Samsung’s success as a foundry shouldn’t be surprising. It’s ethnic Chinese that have spread out throughout SE Asia and started businesses by any exigency and in many cultures. This is what TSMC and other Taiwan foundries started from but on an Island that has been most other ethnic Chinese yet, that is very cosmopolitan and open.
In short, it’s not even mostly a technical issue – it’s non-technical issues related to history, economics, culture, and sunk costs.