I would imagine that the legality of prostitution in the Federation is a matter determined by
local law and custom.
In Risian space, for example (and I'm assuming here, despite
Timo's reasonable speculations, that Risa is a Federation member), it's not only legal, but considered on some level sacred—akin, perhaps, to the [purported but now disputed] practice of priestesses in and around certain ancient Canaanite temples dedicated to a fertility goddess, such as Ishtar. The Horgon—and we'll avoid discussion of
that particular name's ironically punny significance—seems to suggest this as a distinct possibility. There did seem to be an undercurrent of incredulous delight from certain Starfleet officers as related to Risian ... ahem ... generosity—as in, "Well, if I can get laid
and help them stay in good graces with their gods, it's a win-win situation!"
At the spectrum's opposite end, I have little doubt there are Federation member worlds that consider prostitution an affront to the individual's dignity (or an offense against God/the gods) ... and, ironically enough, rather than leaving such decisions up to said individual, have instead outlawed the practice. No doubt such planets are slightly less popular tourist destinations than the aforementioned Risa. Of course, it may be just those planet's inhabitants that make Risa
so popular.
Additionally, whether we like it or not, the introduction in
TNG of the holodeck, and its more-than-implied ability to facsimile willing—and, it would seem, completely convincing, at least to some—sexual partners to
exacting specifications would have dealt prostitution a serious though clearly not lethal blow, if Risa's continued popularity is any indication.
The idea that a truly evolved sensibility would
necessarily gravitate towards acceptance and endorsement of prostitution, though, is absurd, and presupposes certain conceptions about the act's nature as fact. One could argue that atheism would incline a society to accept prostitution, because there's no perception of, say, a stodgy Overseer frowning on or forbidding the practice ... but that humanism might by and large reject it because of the potential for objectification.