No livro, Sauron nunca aprisionou Gandalf (então a resposta é porque isso seria prejudicial para o prequels de Peter Jackson ):
No tempo do Hobbit (ou antes), eles se encontraram duas vezes, primeiro em 2063 quando Gandalf foi para Dol Guldur e Sauron (então conhecido como Necromancer) fugiu porque ainda não estava strong o suficiente ( isso não é coberto em "O Hobbit", mas em "O Senhor dos Anéis", Apêndice B, "A Terceira Era", apesar de ter acontecido durante o tempo em que Hobbit estava acontecendo .
Segunda vez, durante a missão a Erebor, o Conselho Branco ataca Dol Guldur, onde Sauron retornou novamente. Ele "foge" novamente ( mesma fonte ).2063 - Gandalf goes to Dol Guldur. Sauron retreats and hides in the East...
2850 - Gandalf again enters Dol Guldur, and discovers that its master is indeed Sauron. who is gathering all the Rings and seeking for news of the One, and of Isildur's Heir. He finds Thráin and receives the key of Erebor. Thráin dies in Dol Guldur.
2941 - ... The White Council meets; Saruman agrees to an attack on Dol Guldur, since he now wishes to prevent Sauron from searching the River. Sauron having made his plans abandons Dol Guldur.
Além disso, Gandalf conta como os últimos eventos em Dol Guldur aconteceram durante o Concílio de Elrond:
But Saruman has long studied the arts of the Enemy himself, and thus we have often been able to forestall him. It was by the devices of Saruman that we drove him from Dol Guldur. It might be that he had found some weapons that would drive back the Nine ...
... 'Some here will remember that many years ago I myself dared to pass the doors of the Necromancer in Dol Guldur, and secretly explored his ways, and found thus that our fears were true: he was none other than Sauron, our Enemy of old, at length taking shape and power again. Some, too, will remember also that Saruman dissuaded us from open deeds against him, and for long we watched him only. Yet at last, as his shadow grew, Saruman yielded, and the Council put forth its strength and drove the evil out of Mirkwood and that was in the very year of the finding of this Ring: a strange chance, if chance it was.
'But we were too late, as Elrond foresaw. Sauron also had watched us, and had long prepared against our stroke, governing Mordor from afar through Minas Morgul, where his Nine servants dwelt, until all was ready. Then he gave way before us, but only feigned to flee, and soon after came to the Dark Tower and openly declared himself.
Eles nunca entraram em conflito diretamente na linha do tempo do LOTR, a única vez que Gandalf foi preso foi por Saruman - veja abaixo.
Agora, no caso de você ter se referindo a Saruman (não a Sauron), que, de fato, prendeu Gandalf (durante o tempo da LOTR):
Saruman esperava que Gandalf lhe contasse onde estava o One Ring.
'He was cold now and perilous. "Yes," he said. "I did not expect you to show wisdom, even in your own behalf; but I gave you the chance of aiding me willingly. and so saving yourself much trouble and pain. The third choice is to stay here, until the end."
' "Until what end?"
' "Until you reveal to me where the One may be found. I may find means to persuade you. Or until it is found in your despite, and the Ruler has time to turn to lighter matters: to devise, say, a fitting reward for the hindrance and insolence of Gandalf the Grey."
(The Fellowship of the Ring, Chapter II: The Council OF Elrond)