What was the first law passed by a government (e.g. not a private organization's policy) requiring some kind of licensing or certifications for civilian pilots?
What was the first law requiring licensing or certification for pilots?
Connecticut, a pioneer State for aviation, passed an act on June 8, 1911 to regulate aircraft registration, identification, and pilot licensing: "An Act concerning the Registration, Numbering, and Use of Air Ships, and the Licensing of Operators thereof."
According to connecticuthistory.org:
The Connecticut statute was the world’s first aviation law, and it quickly became the model for similar laws in other states. The law was enforced at first by the Secretary of State, and later by the Commissioner of Motor Vehicles, who for a while doubled as the state’s Commissioner of Aviation.
The full text is available at Connecticut State Library, page 1348 and following:
Other States followed, e.g. in May 1913 the NY Times published this:
This answers the OP though this is not an exam or a certificate. But such certificate were issued as early as 1909/10 by the Fédération Aéronautique Internationale. I don't know if they were required by law nor when. However they were required to participate to airshows and air races under the auspices of the FAI (airshows and races were common in Europe during this era).
According to this FAA information: "On April 6, 1927, William P. MacCracken, Jr., Assistant Secretary of Commerce for Aeronautics, received Pilot License No. 1, a private pilot license."
This license was issued as a "...result of the Air Commerce Act of 1926."
Excerpt from the Air Commerce Act of 1926, pertaining to the issuance of Airmen Certificates: