ST has always taken the modern liberal view of religion: superstition, useless, ignorant, savage. Before Deep Space Nine (DS9) it was never portrayed positively in any episode of ST that I can recall. Most of the time, a religious person was portrayed as an ignorant savage.
In the case that comes to mind, the Star Trek: The Next Generation (TNG) episode Who Watches the Watchers?, Liko (played by Ray Wise) thinks that Captain Picard is "The Overseer", the god their culture forgot about long ago, and calls him "the Picard", and him and his cronies perpetrate various bad things on the crew of the Enterprise, up to and including shooting Picard with a bow and arrow. Religious nuts! What can you do about them?
(And here is what I used to prompt my memory about the particulars, including Ray Wise's last name.)
In DS9, however, the writers had a bit of a problem. See, the Bajorans worship the "Prophets", and the central pillar of their society is their faith and spirituality. This is how they were set up when the race was first introduced (in the TNG ep Ensign Ro) and it was canon, so the writers couldn't just hit CTRL-Z and remove that.
Commander Sisko, at the start of the series, is considered the fabled Emissary by the Bajoran religious leadership, for a variety of reasons, which is one reason he ends up commanding DS9 in the first place.
Sisko--in the series pilot--discovers that the "Prophets" are in fact aliens who live inside the alternate space inside the wormhole that exists between the Bajor system and the Delta Quadrant of the galaxy. This space doesn't have a time vector, the way we understand it, so the aliens don't understand the notion of linear time but they can see our past, present, and future with equal ease (hence, "Prophets").
The Bajorans have these artifacts, mystical "orbs" which--when gazed upon--grant the viewer a telepathic link to the Prophets, which the Bajorans think of as holy visions, "communing with the Prophets"; and it's a great honor to be allowed to use one of the orbs.
So you see, the Bajorans aren't ignorant savages, after all. Their religion is founded on the worship of beings which have a provable existence.
And people who point to DS9 to show that the ST franchise is not hostile to religion completely miss the entire point of religion, much the same way the writers did.
The point of religion--at least in advanced civilizations, which the Bajoran civilization is--is not praying and worshiping and hoping God doesn't crush you like a bug or that He'll get you a girlfriend. It's about faith; and it's about doing the right thing even though it doesn't get you anything other than the good feeling of knowing you did what was right.
The Bajorans don't pray to the Prophets because they're afraid of angering them. But they also don't pray to them because of faith. They do it because the Prophets have demonstrated a willingness, in the past, to help them in various ways. The Prophets, being pandimensional aliens, don't actually desire, require, or care about the worship, but when one of the orbs opens a telepathic comlink, the Prophets usually exchange information with whoever opened the comlink.
There is no faith there because the Prophets prove they exist.
Granted: primitive religions often worship gods in the hope that the gods won't be angered. Worship is about appeasement, not faith. But that's not the kind of worship I'm talking about, and it's not the kind that ST usually deals with anyway.
Who Watches the Watchers? gets off on a technicality with that last--Liko is from a primitive culture (but oh! Not so primitive that they hadn't rid themselves of religion before Picard's unwitting interference). But religions in more advanced cultures never get any better press from ST...except for Bajorans.
The Bajorans are not in a religion, not one based on faith; to the Bajorans, it's a quid pro quo: I worship you, you help me solve problems with my life in a highly direct fashion. It's really more like a Cargo Cult, really--a relatively primitive society building a religion around something that's actually prosaic.
To the Prophets...I don't know what they get from it, to be honest, and the issue is never really dealt with as far as I recall.
Christianity is not based on quid pro quo; you have faith that Christ died for your sins, and you have faith in God. You may, or may not, witness miracles, but the miracles will ultimately be explanable if investigated seriously. You don't get any proof of God's existence or the divinity of Christ.
Islam and Judaism are also not based on quid pro quo. Mostly they are rules for living according to God; the practitioners of those religions--like Christians--don't get anything for it, not in this life. Buddhism is about the same, as well.
And, come to think of it, Wicca and paganism are nearly the same. It's less true of primitive animist religions like Japanese Shinto, where you make offerings to gods when you want to ask for something--and ignore them the rest of the time.
Faith is about believing in spite of the lack of proof, not because your deity shows up every other week and gives you candy. The latter kind of deity might be an actual god and it might just be some kind of superior being, but worship of it is not a religion; it's a cult.
ST has not, as far as I know, ever dealt with any modern religion; it has referred to them through the use of allegory in some cases. But the undercurrent is there.
It's part of the socialist utopia that is the ST universe. Religion has no place in a socialist utopia. The State is your god.
...but we give the Bajorans a pass because their religion is founded on worship of pan-dimensional aliens who don't mind proving their existence.
I mean, even the Klingon religion about Sto-Vo-Kor and Kahless gets munged up by the writers. In the TNG episode Rightful Heir some Klingon monks (Klingons got monks?) clone Kahless. WTF.