>Like what exactly is a replicator, and how does it work?

It takes matter, and rearranges it into something else less boring. Using science. Ish. Things. Lasers.

>Can anybody replicate anything on them?

Depends on the episode.

>Including weapons and drugs?

I think certain weapons were impossible to replicate but you certainly could crank out as many guns and knives as you liked. But of course, being a utopian society, such things would be unthinkable, so it's not an issue.

>If not, who decides what they can make, and how do they enforce it?

Nobody. It's a perfect society. Everyone is nice and peaceful because they choose to be. No wars (with other humans - aliens are fine), no famine (except for that one thing in the original series), no money (or something). They just use the replicators and holodecks for aggressive but entirely wholesome and not at all sexual sports and research and interactive fiction, because the humans of the future have evolved beyond the need to be interesting. Except for Barclay. And La Forge, because one time he created a holodeck model of this girl he had a crush on. Which was awkward when she showed up and he had forgotten to close his porn folder.

>They presumably require energy, and where does that come from?

...subspace or something. Dilithium. Quantums. Shut up.

>Is there a limit to how much stuff a person can make?

Probably just the size of the replicator console thing. And energy. By Voyager they had entire starships made up of holograms so who knows?

Like a lot of post-scarcity ideas, to me, Star Trek essentially ran on magic. A lot of that had more to do with the necessities of sci-fi on a low budget (the only reason transporters existed, for instance, was to they didn't have to spend effects money on shuttlecraft) than thinking hard about actually making it work. It just did. The holodeck, literally, could create self-aware sentient beings if you asked it to. Riker got cloned when a transporter beam reflected off the clouds of a planet or something. The Enterprise got pregnant and had a space baby. That was a thing that happened.

No one cared enough about science fictional speculation to actually try fleshing things out, because that would take time, cost money, and potentially mean taking dramatic risks. Rather, they just came up with a new particle, or kind of energy, or swirly whatever, of the week that would defeat the monster, or other swirly whatever, of the week. Now and then they would just drop the ball on some potentially awesome plot points, like the aliens invading from subspace that snatched people out of their beds and did surgery on them (real creepy stuff) or the Ikonian Empire (apparently a big deal, left magic portals everywhere, completely forgotten about) or the parasites mind-controlling certain Federation higher-ups (leading to the only head-explosion in Trek history.)

But the truth is, the "science fiction" was just stage dressing for utterly banal drama. Probably the books got into it more deeply. The Borg was nice though, until it wasn't.

Edit: I shouldn't say 'no one cared.' Reading blogs by people like Doug Drexler, clearly a lot of people cared, just all too often the plot didn't seem to permit much complexity or insight.