Wolfspider
Explorer
It would have been much smarter for the PCs if they had fought through all the dragon's minions before confronting it, right ?
No, the characters did a very daring and intelligent thing by going right to the dragon. In character, it was the right thing to do That still doesn't mean that it was the right thing for them to do in a metagaming sense.
There is an in-game reason to go through an adventure in sequence. You get the experience and magical items and knowledge you need to overcome the big baddie at the end of the adventure. Often adventures are designed linearly so that characters can claim these things (dragonslaying swords, command words, monster weaknesses) before having the climactic encounter.
There are also the feelings of the DM to consider. He's supposed to have fun, too, right? Well, it's hardly fun for the DM to have all of his preparation and hard work go to nothing and for the DM to have to run an encounter he hadn't thought the characters would reach on the fly.
You have to balance the freedom of the players to determine their own fates with the needs of DM to provide a challenging adventure.