Yes, this is legal. The government has substantial power (called the "police power," though most of it has to do with health, safety, and quality of life generally, not policing per se) to pass ordinances and laws for the public good, such as in regards to sanitation and health, and is NOT required to take account of the effect on current homeowners--and the effect on current homeowners (e.g. devaluing their land) is not grounds to invalidate or avoid the effect of the law. All you can do is pursue the variance; or spend the money for some other sewage disposal solution (e.g. running a line to the nearest public sewer, if possible; possibly composting or electric toilets, which dispose of the waste in another way); or reduce your price enough that someone else will take on the headache of dealing with the situation; or possibly look into entering into long-term leases for the property, not selling (since if ownership does not change hands, you should still be good).