Two witnesses go to the beit din and claim that so and so violated the sabbath on a biblical level. The witnesses claim they warned him in accordance with the rules and they did their part as witnesses. When so and so is brought to beis din, he claims he did a melacha (such as digging a hole), but he claims it was for the dirt. Which would only be a rabbinical prohibition because it's a מלאכה שאין צריכה לגופה. If a person were to use this as their defense to deflect the death penalty would it theoretically work?
Rashi on התיר עצמו למיתה:
Part of his warning was his acknowledgement that he will be killed for what he is about to do. So he admitted he is not doing it in a rabbinically prohibited way as part of accepting his warning.
The Maharsha (Bava Basra 119a) addresses this question and answers that even though the person is theoretically exempt according to R' Shimon, he is still liable to be killed in a court if the witnesses were not made aware of his intentions at the time that they warned him:
Perhaps the Maharsha would concede that the person would be exempt from punishment if the circumstances at the time of the m'lacha act suggest it was likely a m'lacha she'eina tz'richa l'gufa.