There's two questions wrapped up together here that need to be separated:
So if a character does something evil but they can justify their actions as good are they themselves still of a good alignment?
- If they commit an evil act, but it can be justified as good, is the act still evil?
- If a good-aligned person commits an evil act, are they still good-aligned?
I'll answer these separately.
I also won't delve into the specifics of judging whether the Treeloff scenario really involves an evil act. When the roots of the game lie in constantly fighting and killing monsters for loot, when exactly murder is and isn't evil becomes a pretty sticky subject. D&D's alignment system is a bit of a rabbit hole I don't want to dive too deeply into. I'll assume that's a just a concrete example that's tangential to your main question, because there's a more straightforward example available anyway: creating undead.
To #1: Evil acts are always evil, no matter what.
Morality in D&D is different to real life morality.
In real life, good and evil are constructs of human mind and language, and whether a given act is good or evil is a subjective matter we could spend a long time debating. Morality doesn't really exist in the universe beyond that: if life and language vanished, you would not be able to point to something that is objectively evil, things just are. (Depending on your own philosophies this summary might be inaccurate or oversimplified, but to go further would be beyond the point of this answer.)
In D&D, however, good and evil is an inherent and objective property of the universe, just as much as gravity. Evil acts are evil no matter what.
Consider the spell Create Undead, which has the Evil descriptor and is therefore an evil act. Creating undead isn't an evil act because people think it is. It's the other way around: by fundamental properties of the universe, it's an evil act whether people think it is or not, and people consider it evil because it is. Creating undead and trying to justify it as not evil is akin to jumping off a cliff and trying to justify that you shouldn't fall, and doing either is probably a display of insanity.
So if you murder someone as an evil act, no matter why you did it, it's still an evil act.
To #2: Evil acts do not instantly affect alignment.
Actually, this could open up plenty of argument. There mere discussion of alignment is a minefield for fervent debate, because no two people will likely completely agree on how it all works.
But, in general, if your character is good, it will take a series of evil acts to become evil. Your alignment does not correspond simply to the alignment of the most recent action you took; it corresponds to your history and nature.
Most of the time a character simply won't commit enough evil acts to go from good to evil, because it would be against their nature to perform those acts in the first place. If they do, though, their nature is clearly changing, and that should be reflected by an alignment change. Treeloff might be getting corrupted by anger, and may be on the path to become an evil being, which is an awesome storyline in itself.