This is a bug in Rednaxela’s kd-tree. I created a PR to fix it in his bitbucket a few years ago, but no response.
IIRC, This bug happens when points are so concentrated that spliting happens more than once in one call, which is not considered at all. That’s why it happens so rarely, and only with some set of dimensions.
Feel free to use my Kd-Tree, it has protections against infinite splitting and is similar performance to Rednaxela (perhaps even better in mixed workloads due to cache locality).
Sorry for answering late; I actually wrote an answer but I suppose there was a problem with Wi-fi. WhiteFang has already started to use it and there is also range search in your tree which is wonderful.
What my tree doesn't have is the nearest neighbor iterator feature, where much of the cost of searching is deferred to the iteration over the results so if you don't need all the points it doesn't need to do a full search. This could be added, but would be fairly tricky.
If there are any other things you think my tree really needs, let me know and I'll see what I can do. Only thing I'm not interested in at the moment are balancing, and reclaiming memory from removing points.