Exodus 21:2
1 “These are the ordinances that you will set before them: 2 “If you buy a Hebrew servant, he is to serve you for six years, but in the seventh year he will go out free without paying anything. 3 If he came in by himself he will go out by himself; if he had a wife when he came in, then his wife will go out with him. 4 If his master gave him a wife, and she bore sons or daughters, the wife and the children will belong to her master, and he will go out by himself.
Leviticus 25:42
40 He must be with you as a hired worker, as a resident foreigner; he must serve with you until the Year of Jubilee, 41 but then he may go free, he and his children with him, and may return to his family and to the property of his ancestors. 42 Since the Israelites are my servants whom I brought out from the land of Egypt, they must not be sold in a slave sale. 43 You must not rule over them harshly, but you must fear your God. 44 “‘As for your male and female slaves who may belong to you—you may buy male and female slaves from the nations all around you.
Notes and References
"... The laws of manumission of servants are found in three texts: Exodus 21:2-6, Leviticus 25:39-46, and Deuteronomy 15:12-18. While the sections in both Exodus and Deuteronomy speak of six years of service and release in the seventh, the passage in the so-called Holiness Code of Leviticus 25 speaks only of release in the Jubilee year. Scholars have long debated the chronological priority of the three codes, although nearly all maintain that the author of the passage in Leviticus was familiar with the formulation of the law in Exodus, and reuses language that he found there ..."
Berman, Joshua Inconsistency in the Torah: Ancient Literary Convention and the Limits of Source Criticism (p. 122) Oxford University Press, 2017