1. Ignore religion altogether. Either cover up the sound of chanting with the thwack of swords and thud of hammers, or bury it in techno-geekery. Any religious figures encountered in the fiction will be cardboard figures there for background and scenery, dressing the stage upon which the main characters perform. My guess is, a lot of writers who ignore religion this way are themselves non-religious. They don't get it, so to speak, so they just write what they know.
2. Make fun of religion. Sometimes religion, as such, is seen as something that more enlightened people have managed to rid themselves of -- the high technoids who can build spacecraft, or the adepts of mind or magic who don't need the crutch. Any religious figures encountered will be bigots, bozos, or (as the plot requires) potential escapees from the clutches of their primitive religious upbringing. My guess is, these writers loathe religion, at least as they see it being practiced around them.
3. Take a syncretic point of view. Many of your better fantasy and sci fi writers have characters who practice their religions. They may even include supernatural figures as either motivators or characters in their fiction. One common approach is to assume that all religions are equally true -- a "tour of the multiverse" sort of approach." One need not portray the beliefs, practices, or gods of any current religions this way; although those who do will have the problem of what their readers will think of the historic contest of religions that has produced the world we know. A lot of writers who are good at portraying religious characters with some sympathy are nevertheless hostile in their portrayal of Christianity or similar exclusive, monotheistic religions. After all, Christianity in particular and similar, fictional religions would have adherents who did not think that all religions were equally good, or valid, or true.
4. Try to present all believers' points of view. This has been a hallmark of Anderson's work, whether we're talking about The Merman's Children, The Broken Sword, Three Hearts and Three Lions, The High Crusade or The King of Ys. His pagans like their paganism; their objections to the Christians they meet are their objections to Christians they know in the fictional world, not merely the writer's objections to the Christians he or she knows in the real world. Likewise, Anderson's Christians are believably drawn, faults and virtues alike. Their point of view is fairly presented. Given the fantasy or sci fi context, there are things depicted which none of us believe are really possible in the world as we know it -- including supernatural beings and magic. But the characters are drawn true, not merely to show the writer's prejudices.
Mary Stewart's Merlin series also did this well, I think. Among science fiction shows on TV, Babylon 5 treated religion and the supernatural fairly, if woodenly. Deep Space Nine -- at least, once it found its feet -- did the best depiction of how religious people see the world and struggle with things of any show, fantastic or realistic, on TV.