Sometimes, the reason is legitimate. In the older days of gaming, when the "Blind Idiot" Translation ruled, games with lots of text might be too hard to translate (though this is a very weak excuse in today's world). Some things are just too flippin' weird to be understood outside their home nation by most people, as some cultural differences can get a series in hot water if what's tolerated or even welcomed in one country is taboo in another. Sometimes, what's being made is for something that's used differently elsewhere (read: most Japanese cellphone games). Then there are simply the times where the company thinks it wouldn't sell well. Another legitimate reason is, well, legal reasons, especially concerning the licensing of characters appearing in a Massive Multiplayer Crossover (keep in mind that copyright laws are often much laxer in Japan than those of other regions). And finally, with video game remakes and re-releases, some companies, most notably Sony, require a certain amount of new content before they'll agree to import it.
Another thing is that video games have a larger price tag in Japan than in the US, to the point that it is cheaper for Japanese people to import games from the US rather than buying them in their home country. This makes lots of Japanese developers afraid to sell any content that probably would not be more successful in the US than in Japan. This may also explain why some Japanese video game companies (such as Toaplan) release their games in Japan and in the popular PAL territories (Europe and Australia) but not in the US.
However lots of Japanese companies that sided with Nintendo have immediate connections with the US market (due to historical reasons). This is one of the reasons why many old Japanese games were never released in Europe and Australia. Most Japanese companies could not afford themselves a decent exporting company in Europe and Australia after making a US-division.
The opposite, when an American video game company has a EU-division but does not have the money to have a Japanese division or when an European video game company has an American division but not a Japanese division occurs just as often but is often not considered. Perhaps Japanese complain less about shows they don't receive than westerners do.
For anime, there's another justification, coming from the way anime is made. Japan's animation industry is structured very differently from most other countries' — shows aren't made by large companies with centralized legal departments, which are able to sort out licensing issues, but by throngs of small, semi-independent studios, uniting in tenuous and short-lived alliances often meant to produce just one specific series. As the thing goes, when some animators come to an idea of the show, they try to pitch it to some media giant, which, in case of success, just dishes out the money and takes distribution rights. The original production studio then contracts numerous other studios to do animation, music, postproduction, etc., while the distributor handles advertising, merchandise rights and such. So, when the show is finally released, there are sometimes dozens of companies, each holding Copyright to some aspect of it, and sorting these rights for licensing or rerelease may get literally impossible — sometimes even in Japan itself. And until recently, few people even considered the idea that there could be a market for most anime outside of Japan and France. Although even France was not such a dumping ground for anime until 1980 when the Shōnen genre was created, which convinced most French TV-broadcasters that it was a cheap and easy way to fill the kids timeslot that there were releases there.
Well, you might ask, if there is a licensing problem for distribution, how could the show have even been made for broadcast? Wouldn't there have been licensing issues then too? Well, yes and no, and I'm glad you asked that question because it requires explaining about copyright and the general licensing systems cobbled together over the decades that we've had mechanical reproduction on video and sound.
There are two types of licensing involved in a television or radio program, performance licensing and reproduction licensing. Performance licensing, which is needed for broadcast, is easy; networks pay a blanket fee of about 3% of their income to the major performance licensing agencies, ASCAP and BMI, and to a lesser extent SESAC. This solves the problem and they can use any music they want. In the US, use of phonograph records in broadcast doesn't require licensing (which is why radio stations originally started playing recorded music) so that's it; in Europe broadcasters pay an additional fee. So thats it; licensing for the use in a broadcast is automatic and is just a cost.
A broadcaster/cable caster/satellite production company simply makes copies of a work for internal use in production and telecast, they are not distributing copies, so they do not need a reproduction license to make the show or to telecast it. To distribute or sell copies, they do need a reproduction license, which is where the problems come in.
To reproduce a work containing a song in a video, such as a release of an episode of a TV program, they have to get a reproduction permission for the music, and if it was from a CD or other phonorecord, they would need permission to reproduce the record performance also. For example, if someone wanted to use Joe Jackson's "Stepping Out" in an episode of a show, Jackson is both the songwriter and performer so they only have one party to ask. If, however, they wanted to use Manfred Mann's "Blinded by the Light" they would need permission from the songwriter, Bruce Springsteen, and by the performing group, Manfred Mann. (Actually you ask their publisher who then usually asks the artist.)
In the case of someone who wants to make a recording such as a cover version of a song, that's considerably easier (like the example of Manfred Mann's cover of Bruce Springsteen's "Blinded By the Light.") Makers of sound recordings can get an automatic license to do a cover version; if the music publisher won't agree on a license, you file a form with the U.S. Copyright office and sixty bucks, then you pay a fee to the music publisher for each one you sell. The fee is relatively minor, it's roughly 6c per copy or 2c a minute of playing time, whichever is greater.
This automatic license is not available for films; anything you use has to be negotiated with the rights holder directly, for each and every item used. If you miss any and the rights holder finds out, they can get anything from severe monetary damages (potentially hundreds of thousands of dollars) to (in certain cases) "impoundment and destruction" of the infringing work.
So it can be the reason a work isn't released is problems with other parties who worked on it wanting too much money, or being unable to get permission for some of the included songs, or deciding it's too much trouble (or there's considered not enough money to be made in a release) to justify going to the effort and trouble to work out all of the necessary clearances.
But many times it's just none of those reasons, or any apparent reason at all. It could be conveyed as a type of favoritism or nationalism, but for many fans of a series outside the home country, it seems nothing more than a giant middle finger to the rest of the world, with the message, à la the Soup Nazi: "No Export for You!" It just shows that the creators are xenophobic, and it's uncool.
This is considered one of the biggest causes of Internet piracy (you don't have many other choices when nobody will do a legal release). People in isolated areas can get very angry about this, which is why there are other choices.
At the same time, infuriatingly, piracy can also be a major cause of this in itself: while some companies have taken large sales of pirate copies or amount of downloads of their product in an area where it's not currently available as a sign of demand, others may think it's not worth releasing something in an area where people will just buy a cheap pirate copy or download it for free anyway. This is especially true in poorer countries where the population may be perceived as generally unable to afford the full price of an authorized version of a product.