I'm building a plot that requires a specific tree in a forest only suffer harm under specific circumstances, like during a full moon or with a special axe, or (preferably) when a certain object is destroyed. Is there a spell, magic item, or other effect that can do this?
If you want true, full invulnerability, you could have a crafted psionic item that continually produces the effect of the 9th level psion power Timeless Body. It would have a pretty steep cost based on the power level, manifester level, the continuous effect and the no item slot limitation (since trees don't have magical item slots insofar as I am aware). The total cost would be 9x17x2,000x2=612,000 gp and a corresponding amount of xp per the normal magic item creation rules.
Alternatively, and I prefer the flavor of this option more, you could go with an existing process that seems pretty similar, namely the creation of a lich. A humanoid becomes a lich by creating a phylactery in which to store its life force (requirements: Craft Wonderous Item feat, caster level 11+, 120,000 gp, 4,800 xp). The lich/phylactery entry doesn't specify what spells are used, only that the subject be humanoid and a sufficiently powerful spell caster. While a tree is not a humanoid, neither is a dragon, and yet draco-liches are a thing. So, a sufficiently motivated magic user of a certain persuasion could probably come up with a way to make a tree phylactery. That wouldn't make it invulnerable, it would just mean that it'd keep coming back until the phylactery was found and destroyed also.
Glyph of Warding (PHB 236) could be used to prevent access to the area. The glyph is almost entirely shaped by the caster. You could have it be a suggestion to turn around, a blast that destroys those who cross the boundary, or something else along those lines. You can put the glyph on the tree or you could bind it to an item left at the base of the tree. The glyph can be tied to a password to deactivate it or to pass into it without triggering it. I, as the DM, would allow the caster to bind an item as a "key" instead of a password. Doesn't seem like too much of a stretch to me. You could have a magic item generating the glyph every time the spell expires/triggers too so it's not a one and done thing.
Another way of going about it would be to simply create the spell you want to have and seed it into the world. You want your party mage to have access - hint at a grimoire of wards and shielding spells, thought lost but recently found. Speak to the old man in the cave and he'll teach it to you, for a price. Or maybe a mage's guild is holding a seminar covering the new material and all interested parties can attend, limit 100 seats, price per seat 5000 gp. Or maybe your party's mage just skipped that day of wizard college and he has some brushing up to do. It's something he should've known but only will after a bit of rudimentary study.
My point with this one is that you can, as the DM, create what you want and make it a part of the setting. The rules even already allow for players to create custom spells, why can't the DM?