Look at the definitions of law (dictionary.com):
1) the principles and regulations established in a community by some authority and applicable to its people, whether in the form of legislation or of custom and policies recognized and enforced by judicial decision.
2) any written or positive rule or collection of rules prescribed under the authority of the state or nation, as by the people in its constitution. Compare
bylaw,
statute law.
3) the controlling influence of such rules; the condition of society brought about by their observance: maintaining law and order.
I am referring to (1) and (3). When the professor decides that it is a closed-book test, it is a "law". Looking at your notes during the test would then be unlawful.