They were all based firmly in fantasy. Just because they were set in space doesn't change that. The science elements, remember, were fantasy too.
I think you're splitting hairs. But my definition of Fantasy would be more akin to Potter or Lord of the Rings whereas Trek is sci-fi
In other words, fantasy employs zero or very little scientific conjecture or reality to the plot where as Trek [or other sci-fi] attempts
to make make their 'science,' plausible at some point in the future.
Nonetheless I agree Trek has some fantasy elements - the magical crystals that power the ships being one. And some of the omnipotent beings they come accross through the series.
Just to be clear, Dilithium crystals do not "power" the starship, they help regulate and control that matter/anti-matter reaction within the engines.
Here's the thing about stuff like that, I view that as more of a crutch, than a decent into pure fantasy. We don't know with any certainty how to control such a reaction, so they invent something that might do just that. The same is true of the transporters, the Heisenberg Conpensators are technically fantasy, in that they don't exist. But it is more of an acknowledgement that they don't know how to fix the problem, but say this is what you'd have to have in order to make the technology work. Science Fiction is not science fact. It speculates about the technology without always having the answers.