There is no law that makes UL certification mandatory.
However, in the U.S., all electrically controlled equipment or systems must generally be approved under the provisions of the Occupational Safety and Health Act (OSHA Article 29 CFR 1910.xxx; CFR: Code of Federal Regulations) and the regulations of the National Electric Code (NEC); in Canada, the provisions of the Occupational Health and Safety Act (OHSA) and the regulations of the Canadian Electric Code (CEC).
As a result of the federal systems of the U.S. and Canada, different states and provinces must comply with different levels of the NEC and CEC, respectively, with individual supplements. This is related, among other things, to the climatic conditions in each state.
Compliance with national safety regulations is demonstrated through what is known as listing/labeling. In listing/labeling, a qualified Certification Organization (CO) confirms after appropriate testing by issuing a label (mark, e.g. "UL mark").
In the U.S., qualified COs are OSHA-recognized testing laboratories. Probably the most recognized is UL. UL stands for Underwriters Laboratories, meaning the testing laboratories of insurance companies. UL tests to UL standards, which have national standards as an integral part. Ultimately, the goal is to minimize the liability risks for insurance companies caused by equipment and the associated hazards (electric shock, fire and mechanical injury). In the U.S., this can quickly result in livelihood-threatening damage awards for manufacturers, vendors and users (companies).