punish (someone or oneself) by (doing something)
To do something as a way of penalizing or disciplining someone or oneself. The boss has been punishing those who disagree with him by loading them with more work than they can handle. For breaking his diet over the holidays, Bob punished himself by only eating vegetables for two weeks straight.
punish someone by something
to discipline someone by doing something. The headmaster punished the children by forcing them to go to bed early. She punished herself by not eating.