Because it's talking about past (the gate is already painted), my answer was:
- I wish I hadn't had painted the gate red.
Which is wrong, because the second "had" is unnecessary.
Could anyone please tell me why?
Sure. Let's look at a somewhat similar version where modal remoteness is not involved, such as:
- 1.) I hope Tom painted the gate red (yesterday).
I used the verb "hope" because it doesn't involve modal remoteness. And so, the preterite "painted" is being used for past time usage.
Now, let's assume that Tom didn't do that painting, and you know that, but you wish that he had, and so, let's now put in that "wish" verb:
- 2.) I wish Tom had painted the gate red (yesterday).
The use of "wish" requires the use of a past-tense to show that modal remoteness, and that is why version #2 has a preterite perfect ("had painted") now instead of only a preterite ("painted") that is in version #1.
The preterite perfect ("had painted") has two past-tenses in it: the preterite "had", and the perfect construction "have/has/had painted". One past tense is used to put the situation of the painting into the past time sphere, and one past tense is used for modal remoteness (which happens to be required by the "wish" verb).
Now, keeping in mind version #2, let's now negate it--that is, Tom did that painting yesterday but now you wish that he hadn't done that:
- 3.) I wish Tom hadn't painted the gate red (yesterday).
So, now, seeing how version #3 is structured, we can copy that structure to give you what you wanted for your original example:
- 4.) I wish I hadn't painted the gate red (yesterday).
Now, compare version #4 to your candidate version in your OP. Your candidate version has an extra "had" in it.
I hope everything is now as clear as mud. :)