The federal government is not bound by local zoning laws unless it wants to be. Federal contractors can be bound to some extent, but a state cannot regulate federal contractors as a sneaky backdoor way of regulating the federal government.
The federal government's own immunity from local zoning laws is pretty simple. Unless Congress has explicitly said otherwise, state and local governments cannot enforce their laws against the United States. Federal agencies often have a policy of complying with state laws, but that's based on the idea that the state law isn't really interfering with the federal government. An agency would be much less likely to voluntarily comply with a state policy that actually interferes with its operations.
Federal contractors aren't automatically immune to state law, but the state can't regulate them as a way to illegally regulate the federal government. A very recent and on-point case was GEO Group v. Newsom, over California's AB 32. AB 32 banned any private entity in the state of California from providing prison or detention services to any customer. That's fine when it comes to state customers, but as applied to federal contracts it would illegally control the actions of federal agencies. Any zoning regulations would generally fall afoul of this, especially when they are designed to make it basically impossible for the feds to perform legitimate federal activities.
At the district court level, there have been a number of cases where local governments have tried to apply zoning laws to federal facilities. A lot of these involve post offices, and a lot of the cases cite entire strings of previous similar cases. For instance, US Postal Service v. City of Hollywood, Fla. cites 7 previous cases. USPS has more recently had a legislative change requiring them to consider local zoning laws and building codes, and GSA has a similar requirement, but that doesn't mean they must always obey them.
I'm unable to tell to what extent leased property can be exempted from state building codes. The post office cases involve a lot of leased property where a post office could be built despite violating local zoning laws or building codes. However, GSA standards say that leased property has to comply with all state and local laws. It's possible there's some statute I missed, or some more recent judicial decision I missed, or that it's just GSA policy not to invoke supremacy for leased property. The federal government can certainly combine contractor operation with government ownership; for instance, most of the national labs use this model.
Also, most of the rules here assume that everyone is basically trying to be reasonable and at most there's an administrative turf war. When a state or local government is specifically trying to interfere with the federal government, the feds and the courts are generally more willing to block them. If a city has strict rules about fire safety because they're in a wildfire area, the feds will be inclined to follow those rules. If a city imposes strict rules about fire safety that only apply to a particular federal facility they hate, the feds will be inclined to ignore the rules.