Hypersmurf is on the right track: Mooks keep variety in the combat portions of the game and demonstrate the value of certain feat choices. The guy with Improved Trip, Close Quarters Fighting, Greater Weapon Specialization, Prone Attack, Combat Expertise, Sunder, Imp Disarm, Spring Attack, etc. is very good at small scale confrontations with single enemies or small groups of foes. The guy with Great Cleave, Combat Reflexes, and a reach weapon is very good at large scale confrontations with groups of weaker foes. Including mooks in a game plays to the weaknesses of the first strategy and the strengths of the second just like lone boss fights play to the strengths of the first strategy and the weaknesses of the second.
The same is true for spellcasters. The armies of mooks play to the strengths of area effect and battlefield control spellcasters. The Evard's Black Tentacles, Solid Fogs, Walls of Ice, Walls of Force, Fireballs, lightning bolts, cones of cold, Firestorm, Flame Strike, etc are made for tackling mooks. On the other hand, single foe combats play to the strengths of save or die/save or screw specialists. Dispel Magic, Ray of Enfeeblement, Ray of exhaustion, Hold Person, blindness/deafness, disintegrate, enervation, slay living, destruction, finger of death, feeblemind, etc are most useful when facing single foes or small groups.
As Henry said, mooks also serve the purpose of giving PCs a chance to display their superior skills. If you're playing Conan the barbarian, it doesn't really work with the concept if every battle you fight is against a powerhouse monster or NPC of roughly similar skill. You want to be able to wade through a legion of enemy soldiers once in a while.
Speaking of wading through a legion of bad guys, that takes a bit of time so if you want to run bad guys who don't necessarily have the ability to stand up to the party's front liners while they do their bad stuff, you'll need a variety of mooks and bodyguards to give them pause.
And there's another thing that mooks do: they show off the power of buffing spells on NPCs. I wrote an encounter with a single druid/Tamer of Beasts with 16 badgers as his animal companions. That didn't look very frightening...until he cast bear's heart on them. Similarly, I ran an encounter once where a group of commoners with bardsong (amplified through a natural horn), bear's heart, and a variety of other buffs made them into quite respectable fighting machines.
And that brings us to the last thing mooks can do: they can humble PCs. When a group of commoners starts seriously threatening a 10th level party, it gives them a bit of respect for the angry mob.
So mooks reward different PC melee and spellcaster feat and spell choices. They make possible different bad guy strategies and abilities. They offer the PCs a chance to show off their stuff and they can also humble PCs.
Long live the mooks!