The gemara says that they would mutilate the horses that were owned by kings upon their death so that no one else can benefit from them, as a way of showing honor to the king. Although the gemara challenges this from the perspective of darchei ha'emori, Tosafos asks why the gemara doesn't challenge this from the perspective of tza'ar ba'alei chaim. Certainly this causes excessive pain to the animals and should be considered a violation of tza'ar ba'alei chaim. Tosafos points out that although it would also seem to be a violation of ba'al tashchis, the explanation for that is clear - it is being done for a constructive purpose of honoring the king, not wasteful, and is therefore not considered ba'al tashchis. But why isn't it a problem of tza'ar ba'alei chaim? Tosafos answers that the honor of the king trumps the concern of tza'ar ba'alei chaim. Tosafos seems to understand that it is certainly a violation of tza'ar ba'alei chaim, just that the honor of the king is a more important consideration.
The Nimukei Yosef at the end of the 2nd perek in Baba Metziah explains that the prohibition of tza'ar ba'alei chaim doesn't apply when it is needed by a human being. If tza'ar ba'alei chaim was an absolute prohibition it should be forbidden to load animals and use them, and certainly to slaughter them for meat. Therefore, the Nimukei Yosef holds that the prohibition is relative to the human need - if the need of the human is greater than the pain of the animal then it is not a violation at all. The Piskei Tosafos seems to take this approach here also that tza'ar ba'alei chaim is only prohibited if there is no gain, but since it is being done for the honor of the king it isn't a violation. It seems that Tosafos would disagree with this approach to the prohibition of tza'ar ba'alei chaim from the fact that they had to answer that the honor of the king trumps tza'ar ba'alei chaim rather than saying that since it is being done to honor the king, there isn't any tza'ar ba'alei chaim.