I'm doing less work on purpose because I feel so much hatred towards
my boss
First things first; deliberately doing less work is unprofessional and not a way to solve the problem.
As a programmer myself, I understand that deep and sustained focus is a necessary part of programming effectively, and that for many developers music is how they attain that focus. If you had said that without the music you're less productive because you can no longer focus as well and/or are constantly distracted by things going on in the background, then fair enough.
But intentionally doing less work will not help your case, and is not an effective way of protesting your employer's directive (if you really want to protest the directive, playing your music over the computer's speakers would be a more meaningful way to do so; if/when your manager complains you can use that to segue into your discussion about the inappropriate nature of your punishment, the importance of music to your productivity, and so on).
That said, your punishment seems both inappropriate and invalid. A firm warning/talking-to would have made more sense, and management really has no grounds for telling programmers that they can/cannot use headphones at a reasonable volume (unless they can demonstrate a causative relationship between headphone usage and reduced developer productivity).
Remember that you're not there to take arbitrary orders from management that have nothing to do with your actual role (and depending upon your location, various laws may prohibit such frivolous directives from carrying any weight). Nor are you there to be treated as a child who loses privileges for being naughty. You are there as an employee to fulfill a specific role and to follow directives that are valid and relevant to that role.
I think you already understand this, which is why the thing about the headphones irks you so severely.
So then what should actually be done? I think first you have to consider why your boss acted as she did. I see two general possibilities:
She cooked up the punishment in the heat of the moment, without really thinking about it, and unintentionally treated you more like a child than an employee.
She's one of those managers who thinks that being a manager means you get to order people to do/not do whatever arbitrary thing you feel like, and has acted as she believed was appropriate.
In the first case, your boss is probably as embarrassed about the situation as you are upset. She would know that she acted unprofessionally, but also feel like there's no way for her to back out of the situation without losing face. Other than perhaps to wait it out, and then rescind the punishment after some time has passed. Though you shouldn't wait for that to happen, as its a tacit acceptance of your punishment; allowing your employer to treat you like a child is just as childish as deliberately doing less work in protest, albeit in a different way.
The second case is more problematic. Your manager holds an incorrect view about what she can and cannot do as a manager, and the situation won't be resolved without disabusing her of it (or deciding that you're happy to play along with it, which doesn't seem to be the case). Which is unlikely to be pleasant, and could easily have a variety of negative repercussions and fallout. In the long run, your firm is better off with managers who do not treat employees like children. But in the short term, getting there may be painful.
You already seem to be in a fair bit of pain over the situation, so that makes the rest a bit more straightforward. You can't simply accept such a petty punishment and work hard so that you have grounds to ask for "permission" to wear headphones again, as other answers suggest. That simply reinforces to your boss that she was right to treat employees like children. Which means she's more likely to keep doing it; and with the resentment you're already harboring it will just be even more upsetting to you the next time she does. So one way or another, this situation needs to be resolved.
To that end you should be prepared to calmly and politely discuss the following points:
- You take pride in your work and are sorry that you made a mistake, and it will not happen again.
- You are willing to put in some extra time or accept whatever appropriate and relevant disciplinary action is fair to make up for your mistake (verbal/written warning, reduced bonus, paycut, etc.; though honestly in this case I think a stern warning is all that's called for).
- The headphones had nothing to do with the mistake that was made, and not having music is detrimental to your productivity as a programmer.
- The directive about the headphones is neither appropriate nor relevant, and you have no desire to be treated like a child by your employer.
How you get into that discussion is up to you. On the one hand, you could just go straight to your boss with it. That's nice and direct, but may result in a confrontation even if your boss is embarrassed about the punishment she handed down.
On the other hand, you could simply ignore the punishment and keep using your headphones. If your boss regrets her actions then she'll likely just ignore it as well, and the subtext of "I will not be treated as a child" should be easy enough to read. And if she doesn't then she'll approach you and you can have your chat.
In any case, you should be prepared for all of the possible outcomes of that talk. Perhaps she'll agree that she acted inappropriately and everything will be fine. Or perhaps she'll become even more upset, and try to send you packing (if she has that authority). Or perhaps it will become necessary to get her own boss involved. Just be aware that there's a worst-case scenario there, and be prepared for it.
But it seems like the one thing you cannot do is nothing; based upon your reaction to the situation, either your employer needs to stop treating you like a child or you need to find a different employer who will treat you professionally. Harboring such a high level of resentment/"hatred" is not a sustainable way forward. You need to see if the problem can be fixed. And if it can, you need to be able to let that resentment go, forgive, and forget.