Shemot / Exodus 21:2 · Drash
כִּי תִקְנֶה עֶבֶד עִבְרִי שֵׁשׁ שָׁנִים יַעֲבֹד וּבַשְּׁבִעִת יֵצֵא לַחָפְשִׁי חִנָּם׃
If you buy a Hebrew servant, six years he shall serve, and in the seventh he shall go out free, for nothing.
Drash דְּרָשׁ
Slaves themselves
A code of law could open with the courts, with murder, with property. The Torah opens with when a servant goes free. A midrash and Kli Yakar explain why it starts here.
Midrash Lekach Tov: Israel was itself a slave in Egypt, and the Holy One, blessed is He, redeemed it and gave it freedom. So the first law is not to enslave a brother for ever, but only until the seventh year. Kli Yakar adds: the brothers sold Yosef (Joseph), and because of it you came into slavery. Yet you were set free, so set free too.
How Midrash Lekach Tov and Kli Yakar explain it
Midrash Lekach Tov If you buy a Hebrew servant
The Torah began with the law of the Hebrew servant because they had been slaves in Egypt, and the Holy One, blessed is He, redeemed them and gave them freedom. Therefore before all else He commanded Israel not to enslave one another with hard labour and not to enslave for generations, but only until the seventh year, as it says: "For they are My servants, whom I brought out of the land of Egypt, they shall not be sold as a slave is sold" (Vayikra / Leviticus 25:42). Therefore the Torah began with the law of the Hebrew servant.
And "if you buy" means "when you buy", as in "if any man has a discharge from his body" (Vayikra / Leviticus 15:2). This is not a command to buy a Hebrew servant. It means: when he comes into your hand, sold for his theft, then you may buy him as a servant. The court sold him for his theft, as it says: "If he has nothing, he shall be sold for his theft" (Shemot / Exodus 22:2). Of one who sells himself it is written elsewhere: "If your brother grows poor with you and is sold to you" (Vayikra / Leviticus 25:39).
Kli Yakar If you buy a Hebrew servant
This is why all the laws begin with sending the servant free after six years. For the Utterances begin: "I am the Eternal your Almighty, who brought you out of the land of Egypt, out of the house of slavery". And here He says: as you were a slave and I gave you freedom, for I redeemed you from the house of slavery, so you proclaim freedom to your servant, sold to you for theft. For you too were sold because of the theft of Yosef (Joseph): the brothers sold him, and things turned so that because of him you went down to Egypt, to the house of slavery. And still you went out free. So you too send your servant out free.
Takeaway
Mishpatim comes right after the Ten Utterances. The first Utterance speaks of the going out "of the house of slavery" (Shemot / Exodus 20:2), and the first law of Mishpatim speaks of a servant's freedom.
Kli Yakar calls the sale of Yosef a theft: so the Torah names it, "whoever kidnaps a man and sells him" (Shemot / Exodus 21:16), and Yosef himself says: "I was stolen away from the land of the Hebrews" (Bereshit / Genesis 40:15).
Midrash Lekach Tov was compiled by Rabbi Tuvia ben Eliezer in the 11th century. He reads "if" (כִּי) as "when": not a command, but a law for the case that it happens.