I don't see the cost of the synthetization machinery as relevant (in this case), either. There is selection pressure to turn off the production if it's not needed, since leaving it running would consume resources to produce something of which there is enough which thus are not available to produce something that is missing, leaving the next processes which rely on the products unable to run, since it is missing all other raw materials except one being overabundant. This may well make several percent of difference in fitness.
However, the cost of replicating the extra gene just in case someone might need it is an additional burden somewhere around a percent of a percent of a percent of cost: a selection pressure exists, but it is significantly lower. It will still lead to loss of the gene, but it will take thousands of times the number of generations to lose an useless gene compared to a detrimental gene, so it's not a significant effect.
Also consider that a mutation usually changes the gene, it does not remove it, so the cost remains unchanged: the change that makes humans unable to synthetisize vitamin C is merely due to a defective gene, not due to a lost gene.
It's more of a case of "use it or lose it": a mutation that causes loss of the ability to synthesize it would be a disadvantage if the product is not available otherwise. But if it is available from food then there is no deletrious effect: the organism can survive in spite of losing this gene, so there is no selection pressure requiring to retain it. Therefore, a mutation that stops it from working may spread through the population.
Still, the food situation can regularly change (for example, the source being seasonal), so the disadvantage is merely mitigated, thus a selection pressure against it still exists: if during the long time it takes to select against the useless gene a situation occurs where it is useful (like a year with bad weather), it will be strongly enough selected in favor to offset its uselessness.
What is additionally required is a bottleneck in which the population shrinks so significantly that the survivors coincidentally lack that gene to produce it. Since losing the gene was not harmful, lacking it could spread to a sufficient proportion in the population.
Then the founder effect in a subpopulation isolated from the main population would make that gene exceptionless in that subpopulation, coupled with the extinction of the remaining population or speciation of the new subpopulation leads to the species universally lacking that gene.