There are few if any watches that keep anywhere close to “perfect” time, but an inexpensive quartz watch will generally be more accurate than a mechanical watch of any price. For example, a high grade of accuracy for a Swiss watch is the chronometer status granted by COSC. The mechanical accuracy requirement for that is -4/+6 seconds per day (think Rolex). The quartz accuracy requirement is +/- 0.07 seconds per day.
The main driver of the price difference is the fact that mechanical watches generally have hundreds of minuscule parts manufactured to tight tolerances and must be assembled, tuned, and tested by hand. Let’s ignore watches that cost more than supercars for a moment and look at affordable industry-standard Swiss workhorse movements. The quartz Ronda 515 is ubiquitous with (ungraded) accuracy of -10/+20 seconds per month and has a replacement cost of $8. The mechanical ETA 2428-2 has a standard (ungraded) accuracy ranging from +/- 12 to 30 seconds per day and has a replacement cost of about $250. To put that in perspective though, it’s possible to get a quality Swiss watch with a 2824-2 or equivalent for under $300 street price, so you know where most of the money is going.
Without economies of scale, the production costs increase substantially. That’s why brands with completely “in-house” movement production generally cost much more, and the limit for that is bounded only in the millions I suppose. Of course, there are precious metals and jewels which can add substantial cost as well, but that’s not generally why those watches are so pricey.