His spirit passed out "of time and space" (i.e. completely out of the created
universe) before it was sent back. Gandalf also receives a new body --
which is somewhat different from the old one; hence Strider, Legolas, and Gimli
don't immediately recognise him when he reappears. In his letters also
Tolkien explicitly says that Gandalf died; and adds that it was Ilúvatar
Himself Who sent Gandalf back. Basically, Gandalf made the ultimate
sacrifice for his friends: he had no idea that Ilúvatar would send him
back.
__________________________________
All that is gold does not glitter,
Not all those who wander are lost;
The old that is strong does not wither,
Deep roots are not reached by the frost.
From the ashes a fire shall be woken,
A light from the shadows shall spring;
Renewed shall be blade that was broken,
The crownless again shall be king.