The Torah states, “VeNikdashti Betoch Bnei Yisrael,” “I shall be sanctified amidst the children of Israel” (VaYikra 23:32), which teaches that one is supposed to give up one’s life rather than murder, engage in illicit sexual relations, or commit idolatry. The Shelah (She’ar HaOtiyot Ot Aleph) presents a Berachah that one recites before sacrificing his or her life Al Kiddush Hashem: “…BaMitzvotav VeTzivanu LeKadeish Et Shemo BaRabim.” As a Berachah related to Mitzvot, this Berachah should be said Oveir LeAsiyatan, before the Mitzvah is performed (Pesachim 7b). In the case of dying Al Kiddush Hashem, the only possible way to make the Berachah is before the Mitzvah is actually performed.
However, Mitzvot which are contingent upon the actions of another must be said after the Mitzvah is performed, lest the Berachah be said in vain should the other party fail to cooperate (see Ra’avad’s Hassagot to Rambam Hilchot Ishut 3:23). Seemingly, this would pose a serious threat to the existence of a Berachah on dying Al Kiddush Hashem because the murderer may change his mind. One can explain, though, that the real Mitzvah is not to die, but rather to be willing to give up one’s life. Thus, the Berachah can be said immediately after the decision is made to give up one’s life, the true meaning of the Mitzvah.