I think Star Trek is just plain wrong there. What else is new?
As I see it, money is merely a formalization of barter. Instead of going up to some fellow and offering him a cow in return for some services, you offer him some money. It scales a whole lot better than selling cows, for sure, and makes accounting considerably easier. Why throw out something that works?
I doubt even a moneyless system will get rid of prostitution. Men want sex, and some women are willing to trade sex in return for something else. Maybe it might not be called prostitution, but it's the same thing.