There are a lot of good points here, but some people are missing something which is, whether the Dennis A. meant it or not, implicit in the question.
Complete metamorphosis (laying aside hemimetamorphosis for a moment) is not just another trait like antennae or an exoskeleton or a tweed jacket. Holometamorphosis (to recap, this is what most people think of as “metamorphosis”, the complete breakdown and reordering of the body in a crysalis) is a huge gamble and not one which can be easily explained away. The organism is static and defenseless for a significant period of time leaving it wide open to predation and the transformation takes an enormous amount of energy. An organism needs a very good reason to do something like this.
Clearly the purpose is to occupy two distinct niches at different times because this is exactly what is achieved, but this is not an explanation in itself, it still leaves us with the original question, why do it? What makes changing niches so valuable that it is worth the risk and expenditure?
The answer is different for different species, but the common factor is specialisation. Even some ametabolous insects (don’t metamorphose) are masters of specialisation (see ants) and the greater question that comes out of this one which also bugs (pun intended although, of course, insects are not bugs) biologists is “why specialise?” Again, it is energetically expensive, so it must have a definite purpose. The best answers I have seen essentially come down to the fact that specialised organisms do what they do better.
So what I’m saying, in a very roundabout way is that a holometabolous insect wants to do two different things really really well (depends on species what those are). In the vast majority of butterfly species, for instance, caterpillars eat like crazy and butterflies eat little or nothing and mate like bunnies for their short lifespan. In this case, the caterpillar is ideally suited to be camouflaged against its energy rich food source, probably greenery, uses very little energy (crawling and eating is pretty low-energy) but doesn’t get very far. It builds up a nice little energy store and then becomes a colourful butterfly. The butterfly has bright colours so it will attract mates but also predators.
It can fly which uses a huge amount of energy but that doesn’t matter because it won’t live very long anyway and it’s much more important to get those eggs into a safe place, away from the vegetation which has most likely already been ravaged by larval forms onto new pastures (remember many insects go through several generations every summer). There is no way that some kind of caterpillar-butterfly hybrid could fulfil either of these roles nearly as effectively (just look at Hans in A Bug’s Life, thus the metamorphosis.
It’s also worth noting that this probably isn’t only a solution to more general insect issues like independence of development or intraspecific competition (strictly speaking it would have to be kin competition to have any evolutionary impact) as there are ametabolous insects which deal with these problems in vastly less energy intensive and risky ways. Natural selection is a harsh mistress, she doesn’t have time for unnecessary messing about. Many species have increased their survivability by overcoming other problems at the same time, changing food sources is a convenient thing to do since you’re already messing with your morphology, but then some organisms do that without metamorphosing.
Eek, bit of an essay there, my apologies but I hope it is helpful for stimulating further discussion.