A slightly broken analogy would be breaking into a house to remove a hornets nest. Even if you do it carefully and not do any damage and what you do is beneficial for the community as a whole, it's contrary to the law.
Of course that wouldn't make it any more legal; but your defence would have a field day with the prosecution I'd imagine.
IANAL but I've watched the first double episode of The Firm, and I reckon I've got a pretty good grasp on how the law works now!
Obviously I consider a house on fire to be analagous to an infected computer, but I do have some protection putting out a fire right? Nobody would sue me for fire damage (as long as I'm reasonable etc).
In general, when you do something you then take responsibility for the consequences of that action. Thus, if there was a tiny fire and you flooded the house with water and foam and caused considerable water damage you may find the home owner suing for damage caused. You could counter by saying you prevented much more damage, but they'd say that a competent fire-fighter would have done that and avoided all the water damage.
The analogy fails (as they always do) because there are specific criminal laws around computer misuse / unauthorised use. Running software on someone's machine without their permission is unlawful.
You may have mitigation if you can claim that the harm from the botnet was more severe than the harm caused by the clean-up-hacking.
It is frustrating. I used to say "Don't fight abuse with abuse", but it's pretty hard to keep that attitude in the face of so much malware and spam.
On the other hand, you can't give a choking person the heimlich maneuver, or perform CPR on someone, without physical contact that could be construed as assault (or battery? not sure) in any other context.
"Messing with" is very subjective.
It's an interesting way to have someone do the dirty work. I would love to see a postmortem writeup.
From a purely philosophical standpoint, you could take a utilitarian approach ala J.S. Mill and say that it would do the greatest quality of good to the greatest number of people to take such action. Granted at the point we're discussing philosophy, we're outside the judicial process which is all that's up for debate here.