Several people have pointed out that "replicators" did not exist in TOS. "Food synthesizer," if you will.
Which really doesn't explain:
A) Surely a "food synthesizer" can make more than food...
B) Even if it couldn't, the dilithium pattern buffer could be stored on the transporter, and then Scotty could beam up a rock from a planet's surface. Since the matter is converted into energy and then reconverted back into matter, why not reconvert the rock into dilithium?