Apple’s proprietary Spatial Audio encoding allows a user wearing Apple headphones to physically move their head while the immersive soundfield remains in place as if the listener is turning in a room with stationary speakers. This system also allows the center channel of a movie to remain in front of the listener, even if they turn away from the screen.
Outside of Apple ecosystem, head tracking is done using discrete head tracking sensors or even webcams.