A) Surely a "food synthesizer" can make more than food...
You mean like "ice cream maker" can make more than ice cream, or "potato peeler" can do more than peel potatoes?
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?
Or into another Scotty? That way, they both
could beam up rocks, and turn them into two
lumps of dilithium. Which they could then beam down and back up again and turn them into starships. And now the Klingons would be facing two functional starships (plus the crippled original one), and would have to beam up rocks of their own that they could turn into Death Stars. Which would be dishonorable, so they'd just go home.