The Hebrew word for "law, statute" חֹק chok, derives from the root חקק. That root can mean "to decree, legislate", but it can also mean "to engrave" or "to carve (out)." What is the connection?
Before researching this question, I would have assumed that the laws were originally engraved in stone or clay, and that would explain the development. But that doesn't seem to be exactly the case.
Klein provides the following entry for חקק:
Aram. חֲקַק (= he engraved), Arab. ḥaqqa (= was right, was obligatory), ḥaqq (= justness, truth, necessity, obligation), Ethiop. ḥeq (= moderate, sufficient).
(While he mentions here the Arabic haqq "truth", there is also an Arabic cognate, huqq, meaning "a hollow place". This developed into huqqah - "a small box, vessel", which eventually entered English as "hookah".)
Klein also notes the related root חקה, which while also meaning "to engrave," more commonly means "to imitate." One definition that Klein provides for this root is "to trace," which seems to be the bridge between engraving and imitating.
However, regarding חקק, the cognates from the other Semitic languages imply that the development went from "engraving" to "set in place." This led to the Arabic "truth" and eventually to the Hebrew chok as well. This also can be seen from the progress of the word chok itself. Note the order of definitions in Klein's entry:
1 something prescribed, enactment, decree, statute, law, rule. 2 prescribed portion, prescribed due.
It didn't originally mean "law" but rather a set portion, a prescription. We see that usage in this verse, describing the portion the Egyptian priests received from Pharoah:
רַק אַדְמַת הַכֹּהֲנִים לֹא קָנָה כִּי חֹק לַכֹּהֲנִים מֵאֵת פַּרְעֹה וְאָכְלוּ אֶת־חֻקָּם אֲשֶׁר נָתַן לָהֶם פַּרְעֹה עַל־כֵּן לֹא מָכְרוּ אֶת־אַדְמָתָם׃
"Only the land of the priests he did not take over, for the priests had an allotment [chok] from Pharaoh, and they lived off the allotment which Pharaoh had made to them; therefore they did not sell their land." (Bereshit 47:22)
It is easy to see how the word for a prescription can turn into a word for a law or rule.
In the Tanakh, we also find the related word חֻקָּה chuka. In Biblical Hebrew it is essentially synonymous with chok. But in Modern Hebrew chukah got a more specific meaning - "constitution."