One interesting point to note regarding this source for the aveirah of tza’ar ba’alei chaim is that Bilam thought that he was hitting his donkey for a good reason. If one has a legitimate cause to hit his animal he may do so, and it would not be a violation of tza’ar ba’alei chaim. Why then was Bilam punished for his actions? Even though his donkey saw the malach, Bilam did not. Bilam thought that his donkey was simply going astray for no reason. Thus he hit it.
Perhaps we can answer that the Bnei Noach are responsible for their actions even when those actions are b’shogeg – and are not forewarned. But the Rambam, in Hilchos Melachim 10:1, rules that this only applies when the person knows what he is doing; he just does not know that it is forbidden. For example, he knows that he is killing another person but does not know that this action is forbidden. In such a case he would be liable for the murder. However, in Bilam’s case, he did not know that what he was doing was baseless torture. So why was he punished for his actions?
The meforshim explain that the purpose of the malach appearing to Bilam, and at first only allowing the donkey to see him, was to send a message of humility to Bilam. Maybe Bilam was called out for hitting his donkey, as it was a wrong action, but he was not actually held accountable for his actions since they were indeed b’shogeg.