Simply put, you are paying for the research and development that it takes to produce the top end framesets and groupsets. It takes a lot of time, trial, drafting, creating, testing, and reiteration of all the above steps to create a marketable product that also performs. (To some extent, you are also paying for the free product that goes to sponsored teams, but that is much smaller slice of the pie).
The good news, especially if you are working from a limited budget, is that you don't necessarily need the top end, current year models, unless you are intending on riding it for quite some time, or you really do need the small edge that the latest and greatest will give you.
The reason for this is that technology trickles down year after year, and/or you can purchase top of the line a couple years later for a much cheaper price. I don't know the exact rate at which technology does move down, but the current SRAM Force group (Their mid range groupset), is probably just as good or better than the Red groupset of a few years ago, because as the Red group evolves to be better, they don't get rid of the older tech, it just bumps down a level and becomes Force, and the old Force bumps down to Apex, etc etc. (That is very simplified, but basically true). Or, because you don't need that slight edge, you can buy a used group a couple years down the line for much less than new.
The same holds true for bike frames. While the newest framesets have all the aerodynamic and construction/design tweaks that hours in the wind tunnel produce, you can easily get a top of the line frame from a few years ago and reap most of the advantages that you would need. For a long time, the gold standard in triathlon frames was the Cervelo P3, which outperformed just about every frame around, even 4-5 years after initial release.
Yes, it's always fun to get the new shiny, but unless you are at the pointy end of the spectrum, you will get much more bang for your buck buying a few years old.