The US constitution’s supremacy clause allows for this too
But because higher governments derive their existence from the support of the lower governments, laws are frequently written to allow opt in by lower governments
California very commonly inverts the supremacy relationship
Municipal level governments don’t practice the county’s laws unless they opt in, and don’t practice many of the states laws unless they opt in
Exceptions apply