The Istari were ordered to remain in, and also stuck in, forms of Men
A description of the Istari is given in the Unfinished Tales. They were given their "Men-forms" before departing Valinor, and thereafter remained in these forms.
Gandalf and the other Istari
Emissaries they were from Lords of the West, the Valar, who still took counsel
for the governance of Middle-earth, and when the shadow of Sauron began first to stir again took this
means of resisting him. For with the consent of Eru they sent members of their own high order, but clad in
bodies of as of Men, real and not feigned, but subject to the fears and pains and weariness of earth, able
to hunger and thirst and be slain; though because of their noble spirits they did not die, and aged only by
the cares and labours of many long years.
"Who would go? For they must be
mighty, peers of Sauron, but must forgo might, and clothe themselves in flesh so as to treat on equality and
win the trust of Elves and Men. But this would imperil them, dimming their wisdom and knowledge, and
confusing them with fears, cares, and weariness coming from the flesh."
Unfinished Tales
How easy would their mission have been if they could have transformed into, say, powerful creatures to take down Sauron's forces? They were stuck in their "Men-forms" because their main purpose was to unite the forces of good against Sauron, not challenge Sauron physically.
[...]; whereas now their emissaries were forbidden to reveal themselves in forms of majesty, or to seek to rule the wills of Men and Elves by open display of power, but coming in shapes weak and humble
were bidden to advise and persuade Men and Elves to good, and to seek to unite in love and
understanding all those whom Sauron, should he come again, would endeavour to dominate and corrupt.
Unfinished Tales
They came therefore in the shape of Men, though they were never young and aged only slowly, and they
had many powers of mind and hand
The Lord of the Rings
So, to answer your question, Gandalf didn't transform because he couldn't transform. He'd "clothed himself in flesh" before leaving Valinor, and remained in flesh till he succeeded in his mission.
Sauron
Sauron, on the other hand, was a corrupted Maia, who came to Middle-earth on his own accord (to join Morgoth). He was able to assume a different form in the Second Age because he wasn't ordered (by the Valar) to stay in one form.
Of course, later on in the Downfall of Numenor, he loses his physical body in the wreck, and is therefore stuck in an ugly-as-heck form1 till he loses this body again after the War of the Ring.

1 Painting of Sauron, done by JRR Tolkien