He wanted to know for sure if there is a God or not? When he heard about the realized one (Buddha) , he came to get his doubt cleared. When he felt nobody would notice him talking to Siddhartha, the Buddha. He asked Gautama "O enlightened one, Please tell me the truth! and truth only. Is there a god?"
Buddha, from his intuition knew that man to be a great devotee of Lord Rama, he looked at that man with seriousness and said "No, My friend. There is no god".
Buddha's disciples that were gathered there were very relieved and joyous to finally know the truth that there was no god. They all started muttering between them, sharing what the Buddha had just told. Whenever a disciple had asked that question to Buddha he would become silent. So they never knew.
His words spread through the whole town, the whole town was celebrating the day on which the truth of NO GOD was revealed by the enlightened. They were finally free of the ideas of hell, heaven and of somebody sitting up to judge one's actions.
It was getting late in the evening, and once again the disciples came back and sat around the Buddha.
There was a materialist who had been an atheist all his life, he had convinced 1000s of people that there was no god, he used to go to the priests and scholars and defeat them in the argument about god.
He too was getting old and little suspicion arose in him, "what if there is god? Isn’t it waste of my life to spread the "NO GOD" message if there is god?" he thought. He was eaten by this doubt, he finally decided to know the truth and sought the enlightened one.
He slowly came up to where Buddha was sitting, and asked him "They say you are enlightened, Please tell me if there is GOD?"
Buddha knowing that man to be an atheist said with firm voice as if he is in firm conviction "Yes, there is God". Buddha's disciples once again were back to confusion.
To think about: In the story why the Buddha told the atheist that “there is god”?
Instead of blindly accepting or rejecting god, we will know whether there is god or not by reasoning, by analyzing, by questioning and from our own life experiences.
We don’t really need a book or scripture or anyone to tell us if god exists or not.
So the Buddha, does not want that we blindly accept even his teachings. He want us to make some effort to find and realize the truth for ourselves.