Because he is not human.
"Gandalf" is an ancient being of immense power, older than Arda (the world where LOTR takes place). His original name is Olorin and he is an Ainu, a primordial spirit or angel from the first race Eru, the Creator, brought into being. Sauron is also a member of that race, before he fell to darkness and became a twisted shadow of his former self.
Olorin is powerful enough to destroy Sauron single-handedly, only he is forbidden from doing so by powers greater than even himself (the Valar, the rulers of Arda under the One). Instead, he can only be present in Middle-Earth as a very scaled-down version of himself, with only a fraction of his full power and knowledge.Why this is so is complicated, but the reason is part of an ancient doom pronounced upon the Elves when they first left the West (Valinor) for Middle-Earth in unpleasant ciscumstances (basically, they rebelled against the Valar and went into self-imposed exile).
Gandalf is meant to only be a guide and counsellor, not a warrior. When his physical body (immune to death from old age, but mortal) dies, or, rather, is depleted of the energy binding it to Middle-Earth in the duel with the Balrog (another long-fallen Ainu, much like Sauron, only somewhat weaker), his spirit flies back to the West, where he is, for his valorous conduct, allowed to return once more to finish his work. He is given slightly more power and returns as Gandalf the White. (Still, that is nothing compared to what he truly is.)