…he shall be avenged (Exodus 21:20)
The second of the four forms of execution is called hereg, in which a condemned criminal is decapitated with a sword. Our verse simply says that the person in question (who, in this case, has killed his servant) shall be executed for what he did; how do we know that the punishment referred to here is beheading? The Talmud in Sanhedrin (52b) clarifies this by analyzing the Torah text. Our verse says “he shall be avenged” (nakom yinakem); Leviticus 26:25, in the Tochacha (the rebuke), says, “I will bring a sword upon you, avenging the covenant” (nokemes nekam). We see from context then that “vengeance” refers to death by the sword. (The Talmud continues by asking how we know it means beheading rather than impaling or some other manner of execution by the sword; such is beyond our scope to cover here.)
The reason capital punishment is imposed in the case of one who beats his slave to death is so that one should not treat his servants’ lives lightly. The master might view them as “property” to do with as he pleases, but they are people with lives of their own.
This mitzvah only applies to courts in the time of a properly-ordained Sanhedrin. It is found in Talmudic tractate of Sanhedrin, page 52b. In the Mishneh Torah, it’s in Hilchos Sanhedrin chapter 14. It is #226 of the 248 positive mitzvos in the Rambam’s Sefer HaMitzvos.