The form of the reasoning is this:
Thesis: Punishing X in this way is wrong
Rebuttal: Don't do X and you won't be punished
On the surface, this is ignoratio elenchi (ignorance of refutation), a.k.a. irrelevant conclusion or missing the point, presenting a possibly valid argument, which is not a proof/refutation in the relevant sense, while intended to be so. As explained in Davies' text:
"In order to refute an assertion, Aristotle says we must prove its contradictory; the proof, consequently, of a proposition which stood in any other relation than that to the original, would be an ignoratio elenchi... "I am required to prove a certain conclusion; I prove, not that, but one which is likely to be mistaken for it; in that lies the fallacy… For instance, instead of proving that ‘this person has committed an atrocious fraud’, you prove that ‘this fraud he is accused of is atrocious"..."
But I believe that there is more going on under the surface, which makes the tactic so popular. In court there is a notion of legal standing, locus standi. To challenge a law a party has "to demonstrate to the court sufficient connection to and harm from the law or action challenged to support that party's participation in the case". In other words, in court the offered rebuttal might work as an objection to the opponent's standing to challenge the law. Transplanted into a public debate this is a catch 22, "damned if you do and damned if you don't": the opponent is either forced to admit that she has no stake in the matter and withdraw, or admit that she is guilty of X, which is presumably discrediting in other ways.
This is a covert attempt at ad hominems known as poisoning the well, providing negative information about the opponent to the audience in advance in order to devalue what they have to say; and the motivational version of bulverism (psychogenetic fallacy), dismissing opponent's argument as due to ulterior motives, in this case trying to avoid punishment for doing X. Of course, taken literally this tactic conflates public criticism with a legal proceeding, but even without that it has the effect of diminishing opponents' input by hinting that their criticism is less significant because they have no personal stake in the matter.