This mitzvah is different from most of the ones we’ve seen so far. The Torah tells us, “when you get a Jewish slave, you must do this and this and this…” All the details are in subsequent verses, but they constitute a single mitzvah.
The use of the word “slave” is unfortunate, as the experience of the Hebrew slave is nothing at all like what the Jews encountered in Egypt or what the Africans and their descendants experienced in America. One who was forced to sell himself (or who was sold by the courts to work off a debt) was more like a hired laborer with room, board and job security. Not only could the Hebrew servant not be given degrading work, if there was only one pillow, the master had to give it to the servant. (See Talmud Kiddushin 20a, that “one who acquires a ‘slave’ actually acquires a master for himself” and the commentary of Tosfos there.) In fact, the position was such that some people chose to stay after their terms of service had expired.
Details of this mitzvah include that the Hebrew slave goes free in the seventh year (or sooner, if the Jubilee year intervenes). A slave who does not wish to go free at the end of his term of service has his ear pierced in the prescribed manner and serves until the Jubilee.
The reason for this mitzvah is that the Jews are God’s people and He desires us to treat one another with kindness and compassion. Circumstances such as financial hardship may sometimes require that a person sell himself (or that he be sold by Beis Din, the court), but that does not entitle the purchaser to abuse his fellow.
This mitzvah is incumbent upon men only, and only at a time when the Jubilee year is observed. It is discussed in the Talmudic tractate of Kiddushin starting on page 14b and in the Mishneh Torah in Hilchos Avadim chapter 1. It is #232 of the 248 positive mitzvos in the Rambam’s Sefer HaMitzvos.