"I find your lack of faith disturbing' Darth Vader announces just before he chokes an imperial officer with a display of force power in 'A New Hope'. Now on one level Vader is completely correct; this is after all only 20 years since the Jedi were wiped out. The Force should be something that's still a matter of fact to the citizens of the Imperium even if its fading into history. That of course though is also where Vader is dead wrong; the force isn't a matter of faith its an objective reality no different from gravity or magnetism. Star Wars is hardly alone though in this misuse of the ideas of 'faith' and 'spirituality'.
Now its not to say that religion and faith aren't discussed in some works of science fiction in a serious manner; or even just assumed to exist without making a huge deal of the subject. In the 'Lost Fleet' series for example you have a form of ancestor worship being the dominant religion and we see the characters take it seriously but there's no treatise as to how this came about and I'm fine with that, not being remotely religious myself.
What is noticeable in 'Lost Fleet' is at no point do the ancestors turn up and intervene to help the good guys out; they are genuinely a spiritual concept that provides solace for some of the characters but there is nothing to provide evidence that they have an objective reality. This alas is not a courtesy always extended to faith by other popular science fiction media; with Star Trek being one of the worst offenders.
In Star Trek: Deep Space 9 we encounter the Bajorans. They are a people with a pervasive faith in what the call the 'Prophets' who are gods by any other name. Much is made of the spiritual nature of the Bajorans and their faith; much like the Force however faith doesn't come into it as much as you might think. The fact is that periodically the Prophets send the Bajorans orbs possessed of fantastical powers(up to and including time travel). Call me cynical but how much faith is involved when your 'gods' periodically send you presents. If this wasn't enough in the very first episode of DS9 Starfleet find out where the Prophets live and meet with them. From this point on faith becomes something of a moot point; when the priesthood has god's address not believing becomes a delusional act.
This is hardly the only time Star Trek decided that 'faith' and 'spirituality' need a helping hand. Commander Chakotay in Voyager meets his ancestor's 'sky spirits', who of course are aliens that periodically visited Earth. Kirk met the gods of ancient Greece and blew up more than one computer playing god. Trek is hardly alone in this either; Stargate SG-1 built an entire series around the idea of gods being objectively real and even Babylon 5 had an actual demonic possession.
So why do writers keep trotting out this idea of 'real' gods? Well leaving aside simply lazy writing(and seriously this is such a tired cliché that if it forms part of any story you are writing you should start redrafting now) I can't help but think that for some of them it's a form of wish fulfilment. We live in age where the Red Sea stubbornly refuses to part and manna does not rain down from the heavens. At the same time science keeps chipping away at the space in which a god might still exist. Perhaps there's a vicarious thrill in having a religion where the believers can turn to the sceptics and heathens and say, 'I told you so'.