Fortunately it isn't working because as others pointed out, "penalize himself" and "donate to charity" concepts aren't directly tied together. Where the donation actually goes is immaterial, so it's not possible to argue that "punish himself" implies "donate to charity" is punishment.
mistake > punish himself > donate to charity to punish himself
Donating to charity as a method to achieve the punishment goal is precisely material in this case.
GP is asking if this method, which contains both a gain and loss, actually results in a punishment with an intended loss.
But to make it worthwhile (aka the reward part of the punishment), the donations are directed to charity since they need to go somewhere. So that's a small reward built into the punishment.
Implies that OP is correct. In order to penalizing yourself you need to do something you consider a punishment. In this case donating to charity...