Gandalf wasn't always a Maia, he started his literary life in The Hobbit as a wizard, an old wise man with some magical powers. Gandalf's role and importance was substantially increased in the conception of The Lord of the Rings, and in a letter of 1954, Tolkien refers to Gandalf as an "angel incarnate". In LotR, Gandalf refers to him being called Olorin in the West. After Tolkien finished LotR and returned to working on The Silmarillion in 1951, he wrote of Olorin as one of the Maia:
With the Valar were other spirits whose being also began before
the world: these are the maiar, of the same order as the Great
but of less might and majesty. Among them Eonwe the herald of
Manwe, and Ilmare handmaid of Varda were the chief. Many
others there are who have no names among Elves or Men, for
they appear seldom in forms visible. But great and fair was
Melian of the people of Yavanna, who tended once the gardens of Este, ere she came to
Middle-earth. And wise was Olorin, counsellor of Irmo: secret
enemy of the secret evils of Melkor, for his bright visions drove
away the imaginations of darkness.
Of Melian much is later told; but of Olorin this tale does not
speak. In later days he dearly loved the Children of Eru, and
took pity on their sorrows. Those who hearkened to him arose
from despair; and in their hearts the desire to heal and to renew
awoke, and thoughts of fair things that had not yet been but
might yet be made for the enrichment of Arda. Nothing he made
himself and nothing he possessed, but kindled the hearts of
others, and in their delight he was glad.