A treehouse outfitted with spears attached to climbing ropes could serve as a reusable defense system. However, there are risks depending on where you anchor the rope—whether to yourself, the tree, or elsewhere. If you miss a throw, you risk getting pulled down, damaging the tree, or even giving zombies a climbing route. That said, if your tree is thick and sturdy enough, and the zombies begin to climb the rope, you could stab them in the head one by one as they ascend.
However, this strategy would be useless in a "World War Z" style outbreak, where zombies pile on top of one another to reach high places. Additionally, in a "Walking Dead" type scenario, where everyone is a carrier and turns upon death, sharing a small enclosed space like a treehouse with friends could be dangerous. If someone dies inside, the tight quarters could quickly turn into a death trap.
P.S. Please ignore the absurdity of the setup in the AI-generated image—it's just meant to illustrate the general idea.
: