I shouldn't have used the word "horrible" when describing a codebase because "horrible codebase" has very different meanings for different people. The code of well-known companies is typically great from a business standpoint, otherwise they wouldn't have become well-known. By this definition, Mt. Gox's codebase was fine right up until they imploded, because the only reason they were large enough to matter is because rolling out features was the highest priority. But you can see how, to some, this is a distasteful definition of "good codebase."
First mover advantage is one of the most powerful forces in the startup ecosystem. The only way to exploit first mover advantage is to be the first to market, which sometimes means skipping many of what programmers consider best practices.
The general principle is that it's hard to grow large by having a bunch of principles, because principles slow you down. Idealism tends to be the opposite of pragmatism, and being pragmatic seems one of the most important qualities for success in business.
There are exceptions to everything, of course, and I'm not claiming that all well-known companies have codebases that most programmers would consider bad. I've heard Google's codebases are pretty good, for example. Viaweb grew large, and I know how obsessive pg is about code quality.
All I'm claiming is that unless the culture of the company has valued code quality from day one, the codebase of a well-known company will generally not be very good. I.e. there's a correlation between being a well-known (read: large) company and having a codebase with more hacks than most would be comfortable with. So it seems to be the default.
Maybe it has nothing to do with the size of a company or how well-known they are. Maybe it's simply that most codebases aren't very good. But it seems to have a grain of truth that business forces tend to push codebases in a negative direction by default. Additionally, it seems like most codebases you see on github are actually pretty good; better than what you'd see at most companies.