# How can I tell what "that" refers to in this sentence?

"Firenze!" Bane thundered. "What are you doing? You have a human on your back! Have you no shame? Are you a common mule?"
"Do you realize who this is?" said Firenze. "This is the Potter boy. The quicker he leaves this forest, the better."
"What have you been telling him?" growled Bane. "Remember, Firenze, we are sworn not to set ourselves against the heavens. Have we not read what is to come in the movements of the planets?"
Ronan pawed the ground nervously. "I'm sure Firenze thought he was acting for the best," he said in his gloomy voice.
Bane kicked his back legs in anger.
"For the best! What is that to do with us? Centaurs are concerned with what has been foretold! It is not our business to run around like donkeys after stray humans in our forest!"
Firenze suddenly reared on to his hind legs in anger, so that Harry had to grab his shoulders to stay on.
"Do you not see that unicorn?" Firenze bellowed at Bane. "Do you not understand why it was killed? Or have the planets not let you in on that secret? I set myself against what is lurking in this forest, Bane, yes, with humans alongside me if I must." (Harry Potter and the Sorcerer's Stone)

How can I figure out what that refers to in this sentence?

In this context, that refers to the best. How OP can tell this is by assuming he should just work backwards from that looking for the first plausible candidate noun that precedes it (not far back, in this case).

As to exactly what the best means here, that's less clear-cut. It's probably easiest to just think of it as the greatest good for the greatest number. Analysing any more precisely is LitCrit, beyond the scope of ELL.

Most importantly, it certainly doesn't mean what was best for Firenze. When someone says they're doing something for the best, it's normally implied they're doing it for the benefit of others, not themselves. It's the same as acting with the best intentions.

Note that it's possible to "overanalyse" exactly what that refers to in such usages. For example, note that it would have been perfectly possible for Bane to have said...

"Acting for the best! What is that to do with us?"

...and it would be pointless debating whether that referred to acting [in that particular way], or to the best.

It's not a matter of language, it's a matter of logic. Firenze is angry about something. He repeated, as an exclamation, "for the best", so it must be whatever was claimed to be "for the best". In context, it's clear it's Firenze's involvement with Harry.