I remember learning that tzaar baalei chayyim only applies to kosher animals and being very surprised and disappointed, but I don't remember the source at all. Does anyone know where this idea comes from, and who holds by it?
This is incorrect. Examples given include loading and unloading a donkey as we see in Tzaar Baalei Chayim Thus, the halacha applies to all animals
In Shemot, we are told to help him unload: “If you see the ass of your enemy straining under his load, and you refrain from unloading it, go and unload with him” Shemot 23:5.
This verse is one of the main sources for the prohibition of causing unnecessary suffering to animals, tza’ar baalei chayim (Bava Metzia 32b). While man was given dominion over the animals (Bereshit 1:26), this dominion is not one of tyranny, and it has limits. Any time we use animals for our benefit, we have to be sensitive to their feelings and avoid any unnecessary pain.
Others refer to Bil'am and his donkey as part of this halacha.
The Rambam, in Moreh Nevuchim (chalek 3, perek 17), writes that this is the Torah source that one is not allowed to cause pain to an animal – known as tza’ar ba’alei chaim. There are many other sources brought in the Rishonim and Acharonim regarding this. Rashi, in Shabbos 128b, says that tza’ar ba’alei chaim is derived from the pasuk in Parshas Mishpatim, “Azov ta’azov imo.” Rabbeinu Peretz, in Baba Metzia 32b, says that there is no Torah source for tza’ar ba’alei chaim; rather, it is a halacha l’Moshe miSinai. The Shita Mekubetzes, in Baba Metzia there, quotes a Ra’avad that says that it is drawn from the aveirah of placing a muzzle on an ox when he is plowing. The Charedim (14:1) says that tza’ar ba’alei chaim is part of the mitzvah of vehalachta bidrachav (and we should follow in Hashem’s ways). The Chasam Sofer, in Baba Metzia there, says that tza’ar ba’alei chaim is derived from the pasuk of “verachamav al kol ma’asav” (and He has mercy on all of His creations).
See the Gemara Chullin 7: that clearly discusses a tzaar balei chayim issue when Rebbi offers to remove the hooves of mules that were at risk of harming others. Although, technically this would not be tzaar balei chayim as there was a clear benefit from behooving them Rebbi was stringent in this regard. One could still argue that he was also going beyond the letter of the law with regard to tzaar Baalei chayim by non kosher animal...