A state law can only be illegal if it violates the state's own constitution or the US constitution.

States are not obligated to participate in the enforcement of federal law, and are entitled to control the official conduct of their own officers and agencies.

If a state has a law that prohibits local police officers from furnishing data to federal agencies, that law is completely valid, and officers that act contrary to it are in violation of state law.