An interesting dvar Torah on parshas Mishpatim that I received:
The Torah tells us that if a sheep or goat is killed while grazing, it is called a treifa and should be given to the dogs to eat. Rashi explains that this is a reward for what the dogs did. When the Jewish People left Mitzraim, not a single dog barked. Since that was a Kiddush HASHEM, for generations all Treifas should be fed to the dogs in repayment for what they did in Mitzraim. How could a dog be entitled to reward?
This Rashi becomes difficult to understand when we take into account that we are dealing with animals. Animals are instinctual in their reactions. Granted, they can be trained to act in a particular manner, but they don't have a conscious 'I' that can sit, weigh the different options, and decide to do or not to do. In all of the physical Creation, only man was given that capacity. So how can a dog receive reward for its actions?
But even more, before this event, HASHEM told Moshe that the dogs would not bark. The Rishonim explain to us that it was a miracle. HASHEM stopped them from barking to further show His glory. Surely they don't deserve reward for something that wasn't even in their control.
Two systems in Reward and Punishment
The answer to this is based on a deeper understanding of reward and punishment. When an act is judged, two components are weighed: the outcome of the act and the intention behind it. The outcome is measured by effect -- what was accomplished? How much? To what extent? Intention is far more subtle -- what was your motivation? What was your meaning? What was your purpose?
Different systems of Judgments
When we judge people, we focus mostly on their intentions. If you intended to harm me, I will harbor ill feelings towards you whether you succeeded or not. Since you meant to harm me, I feel you are owed retribution. On the other hand, if you intended to help me, whether you were successful or not, I still am obligated to appreciate your good intentions.
HASHEM judgment is far more exacting
When HASHEM judges, however, the system is far more exacting. Intentions and outcomes are often separated, each one weighed independently of the other. The reason for this is based on HASHEM’s involvement in this world. One of the most basic tenets of our belief system is that nothing happens by chance. HASHEM created, maintains, and orchestrates this world. In truth, man can accomplish nothing in this world. Every action, every outcome is determined by HASHEM. If Reuvain was predestined to live to be 120, I can neither harm him, nor help him. HASHEM will insure that His decree is fulfilled and I am powerless to change it. To allow for reward and punishment, HASHEM created a system whereby it is considered as if man determined the outcome. If I am the one acting on the scene in certain situations, the result is attributed to me. It is credited to my account -- even though that outcome was inevitable -- because HASHEM had so planned it. In our case above, if Reuvain's time was up, I might well be allowed to be his murderer. I will be held accountable even though his death was decided long before I picked up the gun. I am considered the one who did the act. So too, if a person intended to harm an individual but unintentionally helped them, while he is punished for his intentions to harm another person, there is reward due to him for the good that came from him. Even though he didn't intend that good, it was brought into the world through him, so in the system of reward and punishment, he is credited for that act.
Through the dogs a greater Kiddush HASHEM came about
The answer to the Rashi seems to be that via the dogs, there was a greater Kiddush HASHEM. Anyone, whether Mitzri or Jew, saw a greater revelation of HASHEM because as an entire nation walked out, not an animal stirred. Through the animals a greater good was brought, and for that they deserve reward. Granted they didn't intend it - they are animals - but through them came out a good which is attributed to them, and for that they deserve reward.
------------
I wonder about the case where your intention is to do good, and yet the effect is negative. Do you still get punished? It would seem to follow from the above.

