This question already has an answer here:
The Maia sent to Middle Earth to safeguard it from Sauron were under strict orders: while in Middle Earth, they are to live as mortals, they are not to reveal their true identities, nor are they to engage Sauron or his armies with their true power. These rules are designed to prevent them from dominating the Free Peoples, and to protect Middle Earth from further devastation by another "war of the gods".
When Gandalf faced the Balrog, however, do these rules still apply? Do the Valar require Gandalf to stick by these rules to the bitter end, or are exceptions made for self-defence? After all, as a Maia who had never fought in the wars, his ability to defeat a top lieutenant of Morgoth is objectively speaking in doubt, let alone if he has to "fight as a mortal".