…I would be sanctified among the children of Israel… (Leviticus 22:32)
This mitzvah is the flip side of the previous one. It’s not enough simply to avoid doing unseemly things. Rather, we should behave in a fashion that makes people say, “You know what? Those Jews are okay!” This reflects well on God and His Torah.
Just as refusing to die when necessary is a chillul Hashem, dying to defend the faith is a kiddush Hashem (hence the term “to die al kiddush Hashem”). This is only necessary under the following conditions: when ordered to commit acts of murder, idolatry, or adultery/incest, and during a time of forced conversion imposed by non-Jewish authorities. In other circumstances, one should yield and live rather than die. If, for example, a person were ordered by a random individual to violate Shabbos, he should do so and not throw his life away. The Torah tells us (Levticus 18:5) that the mitzvos are meant to live by, not to die by.
The reasons those three mitzvos are the ones for which we must die are as follows: (1) Murder – logically, why is my life more important than another person’s? (That goes both ways. If lost in the desert with a canteen, I can’t sacrifice myself by giving it away to another person because who says his life is more important than mine?) (2) Adultery/incest – the Torah compares the rape of a betrothed maiden to murder (Deut. 22:26), from which we derive that illicit relations are equally prohibited, even under coercion. (3) Idolatry – if we’re talking about the choice of desecrating vs. sanctifying God’s Name, what could be more of an issue than whether or not to bow down to a hunk of stone?
The reason for this mitzvah is that we are only here because of God. He should be the end-all and be-all of our lives. We should work hard to reflect well upon him and be willing to turn in those lives when necessary, such as if under compulsion to violate one of the cardinal sins.
This mitzvah applies to both men and women in all times and places. It is discussed in the Talmud in the tractates of Pesachim (25a-b) and Sanhedrin (74a-b); it is codified in the Shulchan Aruch in Yoreh De’ah 157. This mitzvah is #9 of the 248 positive mitzvos in the Rambam’s Sefer HaMitzvos and #5 of the 77 positive mitzvos that can be observed today in the Chofetz Chaim’s Sefer HaMitzvos HaKatzar.