Your question is
How does quartz form in calcite veins?
But maybe a more appropriate question will be
How does quartz not form in calcite veins?
Quartz is one of the most common vein material in Earth's crust, and for a reason. SiO2 is not a particularly soluble compound at the surface, but once you get deeper it becomes extremely soluble (source):
The solubility of SiO2 is almost 0 at at 1 bar and 25 °C, but increases strongly with pressure and temperature. For example, at 200 °C and 2000 bar (2 kbar, 0.2 GPa, about 5–6 km depth), conditions that are reasonable for an unmetamorphosed but deeply buried limestone, you can fit about 500 mg of SiO2 in 1 kg of H2O. At atmospheric pressure that's one litre of water, but it's much less voluminous at depth. That is a lot of SiO2! Once the fluid goes up towards the surface, it depressurises and cools, causing precipitation of quartz.
There is no shortage of sources for SiO2. It is the most common chemical component in the crust. Even in seemingly pure limestone there are more than enough impurities of silicates to provide a source for SiO2.
The fact that quartz and calcite occur together in a vein is no problem at all. You might expect them to react, but they actually do not. Here's a diagram to show it (source):
Calcite and quartz can peacefully coexist, unless it's extremely hot and then they react to form wollastonite (a Ca-silicate). This is the kind of stuff you find in high grade metamorphosed marbles, for example.
As an aside, another question that may be asked is why only calcite and quartz? If hot dense water are so good in dissolving stuff? Where's the rest of the periodic table? Well, most of the elements are readily soluble in acidic fluids. In this case, the abundant calcite buffers the pH of the water to rather basic conditions, which are not that great in dissolving stuff.