Sometimes a person is subjected to such a difficult test that it is impossible that he not sin.
As our Sages said [in explaining the sin of the Golden Calf: “This may be compared to a man who had a son. He had him bathed and anointed, he fed him and gave him to drink, he hung a purse around his neck and he put him at the door of a brothel.] What can that son do in order not to sin?” (Berachot 32a).
In such a situation, a person is considered to be completely coerced, in which case the Compassionate One absolves a person.
And so too when a person’s [evil] inclination tempts him with incredible, overwhelming force, that is a situation of coercion. If Hashem compels his heart, his sin was no sin whatsoever. Rather, it was God’s will.
See Ketubot 51b describing a case of a [married] woman who is being raped:
“Even if, at the end, she cries out that should the rapist stop, she would pay him [to continue, she is not considered to be an adulterer, and] she is permitted to return to her husband. Why? Because her [evil] inclination enveloped her.” Thus, we see that this is considered total coercion although [in the end] she was willing.
Thus, when a person’s [evil] inclination is so great that he cannot overcome it, he is [considered to be] under complete coercion. In that case, there is no punishment for [what he has done], even if he performed a prohibited act, because he was coerced.
However, the person himself cannot testify about himself that this is indeed the case, because it is possible that he still had the ability to overcome his [evil] inclination (as I heard [from the Ishbitzer Rebbe] regarding Zimri, who erred in this matter [when he engaged in relations with a Moabite princess]).