There are certain cases in which an animal designated for a sin offering (Chat'as) could not be brought in the Temple, but was required to be killed ("חטאות המתות"), according to some opinions, by starvation. This seems like it conflicts with the Torah's notion of not causing "tza'ar ba'alei chayyim", excessive pain to animals. How can we reconcile this?
Tzaar baalei chayim is usually measured by the ratio of animal pain to human gain. I guess the gain is considered high/necessary enough here?
The Noda BiHudah says directly killing the animal in any normal sort of way, e.g. deer hunting, is not considered tzaar baalei chayim per se. But yes, starvation is more problematic.
The Rambam (Hil. Pesulei Hamukdashin 4:1, from Temurah 15b ff) points out that this is a law given to Moshe (ודברים אלו כולם מפי משה רבנו נשמעו). He may be stressing that point in order to explain how indeed the rules for treating such animals can override the rule about avoiding tzaar baalei chaim.
[It's actually a matter of dispute as to whether the latter is a Biblical-level mitzvah anyway; this is discussed in Bava Metzia 32b-33a, and tangentially in other places. The accepted halachah is that it is (Rambam, Hil. Rotze'ach Ushemiras Nefesh 13:13; Shulchan Aruch, Choshen Mishpat 272:9 in Hagah).]
On a basic level, it may boil down to the fact that killing it outright would be a violation of another mitzvah, that of not slaughtering sacrifices outside of the Beis Hamikdash, a sin which is punishable by kares (spiritual excision). While it is true that this penalty doesn't apply to chataos hameisos (Rambam, Hil. Maaseh Hakorbanos 18:6), that doesn't necessarily mean that it is permissible to do so.