I think what’s happening here is the track-to is flipping when it crosses the Z axis, since it is likely using the Z axis to determine which way ‘up’ is. So when it crosses that axis, it has to rotate 180 degrees to keep the ‘up’ side of the bone pointed ‘upwards’.
My suggestion would actually be simply to not use it. I have seen rigs with a tracking system for the head, but in every case there needs to be some kind of override for it. Tracked heads work for looking around, but it can be tricky to animate a reaction, or an impact on the head (or other scenarios where the head is not tracking, but is being manipulated directly instead). I’ve found in my rigs that leaving the head as a free-rotating bone (double tap r to free rotate) works just fine And you can of course make it a hinge, which can make the animation more intuitive.
In any case, I’m pretty sure the problem is the track-to trying to point ‘up’ in the scene’s global space. If you decide you still want to setup a tracking system for the head, you’ll need to define ‘up’ as being a bone. You can do this on the track-to constraint, or I usually use an IK for this type of thing, since you can define ‘up’ using a pole target (which I imagine you know how to use now ;)). That way ‘up’ is not global, but can move along with the rig as a bone.