And, It IS federal law.
NO. The NEC is NOT Federal Law. If it was a Federal law it would be a CFR (Code of Federal Regulations) and it's not. Local building codes are also not laws. Local building codes generally reference national codes like the NEC and NFPA 101 as the basis of the local code. Local codes may add additional requirements to the NEC, but rarely delete a requirement.
The NEC is also NFPA 70 (National Fire Protection Association) code. There is no police agency that is going to enforce the NEC/NFPA 70. Police agencies enforce laws, not building codes. There is no direct punishment if you decide to not adhere to the NEC. There are certainly liabilities and that may result in consequences of not following the NEC, but those are not direct punishments for not adhering to the NEC.
The NEC forms the basis for local electrical codes as part of local building codes enforced by the Authority Having Jurisdiction (AHJ). In most areas in the United States that is generally a local government agency with a title like "Planning & Development Services Department," or "The City of XXX Planning and Zoning Department," etc. This is not a police agency with the authority to arrest and detain people.
Codes are enforced by the AHJ through construction inspections. If the inspection shows that the installation does not meet the local building code - nobody is arrested, and no one is going to jail. If your installation does not meet code, you cannot proceed with additional work until the work is corrected and inspected for conformance to the building code - that's it.
Most electricians will not do work that violates the code because they can lose their license, and be held liable for any damages associated with the non-conforming work. If the damages can be proven to be the result of performing work that does not conform to local building codes and the NEC, then their liability insurance will not cover the settlement - meaning they have a lot to lose professionally and personally if they do non-conforming work.