The device does not know where the other device is exactly although it knows it is clode because of Bluetooth. It will assume you want to move to the device you interacted with most recently when you move your mouse pointer past the edge of your Mac. From that moment on it will assume the device is on that side.
Source: https://www.theverge.com/2021/6/8/22523613/macos-monterey-ww...