Why, for example, do you have to be a friend of the right broker in order to get in on an IPO?
OK, I'm now going to drift over into financial wonkery. I have to start by saying that I am NOT a registered financial advisor, and that nothing I say should be construed as giving financial advice.
IPOs have a number of purposes, of which "raise capital for the issuing company" is only one. Others are "provide employees with an exit path/reward" and "give the company flexibility to make larger acquisitions with non-cash offerings." See for example Facebook's recent move.
IPOs are risky for buyers. Outside of bubble conditions and outliers such as Google, most IPOs don't significantly appreciate in the short term. Part of the point of pricing an offering is to extract the maximum revenue at offer. Thus they're offered high and often drop significantly in the days and weeks after offer. Again, see Facebook as a salient example. Someone who bought into the Facebook IPO on offer day would have lost a great deal of money compared to someone who waited two weeks and then went to eTrade and picked it up at half its IPO price.
IPOs also require a willing and ready contingent of buyers and sellers. These are entities that commit to put up millions of dollars to ensure that there are enough sales of the offering. If that doesn't happen, the IPO collapses. A good recent example of this is BATS's abortive attempt to IPO. (Full disclosure: I used to work for an entity that was part of the BATS group and I used to own some BATS shares. After the IPO collapse the holding company bought back my shares.)
In order to get entities to be willing to sign contracts for millions of dollars on an unknown and might-collapse-anyway-leaving-them-significantly-poorer deal, you have to offer them a discount. Thus, these entities get blocks of stock allocated to them at less than the IPO price. They, of course, hope to sell those blocks at IPO and make money. If that doesn't happen pain follows, and lawsuits. See again Facebook.
For all these reasons, and more I don't have time to write at the moment, I think that offering IPO deals to the general public is usually a bad plan. I agree that it's frustrating to watch entities that have millions make more millions on IPOs, but that's because we all remember the good IPOs and forget how those same entities lost millions on the last IPO that tanked.
As to the question of whether or not the IPO returns sufficient capital to the issuing company, that's a very individual thing. There are costs to structuring an IPO, not least of them doing the roadshow, doing the SEC dance, and lining up all those initial buyers. The entities (which are usually large investment banks with M&A arms) that can make this IPO circus happen are few and they get to command a high price for their services. They are the neurosurgeons of the financial world - neurosurgeons make a lot more than other surgeons and, I'm told, have similarly awful bedside manners.
There have been a lot fewer IPOs in the past two decades. Part of that has to do with the fact that IPO deals have tilted against issuing companies, part has to do with the fact that IPO deals have gotten harder to structure (due in part to capital flight from equities markets), and due in part to the rise of ETFs, about which more if you are really into this kind of financial wonky deep-dive. The bottom line is that companies have things like CFOs and boards of directors to help them evaluate whether taking the company public is a wise idea. If the responsible people decide it's a good idea then that falls into the category of "feels good to both sides" that I initially started talking about.