KNN tie breakers changing based on the subset of the train

### Describe the bug

According to https://scikit-learn.org/stable/modules/neighbors.html#unsupervised-nearest-neighbors:

**Regarding the Nearest Neighbors algorithms, if two neighbors k  and k+1
 have identical distances but different labels, the result will depend on the ordering of the training data.**

I expect this is also true for KNN without going into classification,  where the scope is only to find the NN without voting the class. However, this code provides me a different ordering for NN based on the selection of the train set. Please note that the last two points I removed should not change anything.

Another strange behavior is that running with k=5 46 is taken, but 5 (minor index) should be selected.

```py
import pandas as pd
from sklearn.datasets import fetch_file
from sklearn.model_selection import train_test_split
from sklearn.neighbors import NearestNeighbors

url = 'https://archive.ics.uci.edu/static/public/891/data.csv'
filepath = fetch_file(url)

df = pd.read_csv(filepath)

y = df['Diabetes_binary'].to_numpy()
x = df.drop(['ID', 'Diabetes_binary'], axis=1).to_numpy()
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42)

x_train = x_train[0:100]
x_test = x_test[0:1]

ml = NearestNeighbors(n_neighbors=6, algorithm='brute').fit(x_train)
d,n =  ml.kneighbors(x_test, return_distance=True)

x_train = x_train[0:98]

ml = NearestNeighbors(n_neighbors=6, algorithm='brute').fit(x_train)
d2,n2 =  ml.kneighbors(x_test, return_distance=True)

print(n)
print(n2)

print(d)
print(d2)
```

``` 
[[33 58 97  2 46  5]]
[[33 58  2 97 46  5]]
[[7.61577311 7.93725393 8.30662386 8.30662386 8.60232527 8.60232527]]
[[7.61577311 7.93725393 8.30662386 8.30662386 8.60232527 8.60232527]]
```

### Steps/Code to Reproduce


```py
import pandas as pd
from sklearn.datasets import fetch_file
from sklearn.model_selection import train_test_split
from sklearn.neighbors import NearestNeighbors

url = 'https://archive.ics.uci.edu/static/public/891/data.csv'
filepath = fetch_file(url)

df = pd.read_csv(filepath)

y = df['Diabetes_binary'].to_numpy()
x = df.drop(['ID', 'Diabetes_binary'], axis=1).to_numpy()
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42)

x_train = x_train[0:100]
x_test = x_test[0:1]

ml = NearestNeighbors(n_neighbors=6, algorithm='brute').fit(x_train)
d,n =  ml.kneighbors(x_test, return_distance=True)

x_train = x_train[0:98]

ml = NearestNeighbors(n_neighbors=6, algorithm='brute').fit(x_train)
d2,n2 =  ml.kneighbors(x_test, return_distance=True)

print(n)
print(n2)

print(d)
print(d2)
```

### Expected Results

``` 
[[33 58 2 97 46  5]]
[[33 58  2 97 46  5]]
[[7.61577311 7.93725393 8.30662386 8.30662386 8.60232527 8.60232527]]
[[7.61577311 7.93725393 8.30662386 8.30662386 8.60232527 8.60232527]]
```

### Actual Results


``` 
[[33 58 97  2 46  5]]
[[33 58  2 97 46  5]]
[[7.61577311 7.93725393 8.30662386 8.30662386 8.60232527 8.60232527]]
[[7.61577311 7.93725393 8.30662386 8.30662386 8.60232527 8.60232527]]
```

### Versions

```shell
System:
    python: 3.12.3 (tags/v3.12.3:f6650f9, Apr  9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)]
executable: C:\Users\Corrado\Desktop\Corrado\Politobox\Research\repository\scalabaleLearning\scalabaleLearning\Scripts\python.exe
   machine: Windows-10-10.0.19045-SP0
Python dependencies:
      sklearn: 1.6.1
          pip: None
   setuptools: 75.3.0
        numpy: 1.26.4
        scipy: 1.14.1
       Cython: None
       pandas: 2.2.0
   matplotlib: None
       joblib: 1.4.2
threadpoolctl: 3.5.0
Built with OpenMP: True
threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libopenblas
       filepath: C:\Users\Corrado\OneDrive - Politecnico di Torino\Corrado\Politobox\Research\repository\scalabaleLearning\scalabaleLearning\Lib\site-packages\numpy.libs\libopenblas64__v0.3.23-293-gc2f4bdbb-gcc_10_3_0-2bde3a66a51006b2b53eb373ff767a3f.dll
        version: 0.3.23.dev
threading_layer: pthreads
   architecture: SkylakeX
       user_api: blas
   internal_api: openblas
    num_threads: 16
         prefix: libscipy_openblas
       filepath: C:\Users\Corrado\OneDrive - Politecnico di Torino\Corrado\Politobox\Research\repository\scalabaleLearning\scalabaleLearning\Lib\site-packages\scipy.libs\libscipy_openblas-5b1ec8b915dfb81d11cebc0788069d2d.dll
        version: 0.3.27.dev
threading_layer: pthreads
   architecture: SkylakeX
       user_api: openmp
   internal_api: openmp
    num_threads: 16
         prefix: vcomp
       filepath: C:\Users\Corrado\OneDrive - Politecnico di Torino\Corrado\Politobox\Research\repository\scalabaleLearning\scalabaleLearning\Lib\site-packages\sklearn\.libs\vcomp140.dll
        version: None
```

COMMENT:
Thanks for the issue and the reproducer!

I can not reproduce on my machine, can you try with the latest versions of all the packages just in case?

Here is the output on my machine:
```
[[33 58  2 97 46  5]]
[[33 58  2 97 46  5]]
[[7.61577311 7.93725393 8.30662386 8.30662386 8.60232527 8.60232527]]
[[7.61577311 7.93725393 8.30662386 8.30662386 8.60232527 8.60232527]]

```

```
System:
    python: 3.12.7 | packaged by conda-forge | (main, Oct  4 2024, 16:05:46) [GCC 13.3.0]
executable: /home/lesteve/micromamba/bin/python3.12
   machine: Linux-6.13.4-arch1-1-x86_64-with-glibc2.41

Python dependencies:
      sklearn: 1.6.1
          pip: 24.3.1
   setuptools: 75.5.0
        numpy: 2.1.3
        scipy: 1.14.1
       Cython: None
       pandas: 2.2.3
   matplotlib: 3.9.2
       joblib: 1.4.2
threadpoolctl: 3.5.0

Built with OpenMP: True

threadpoolctl info:
       user_api: blas
   internal_api: openblas
    num_threads: 12
         prefix: libopenblas
       filepath: /home/lesteve/micromamba/lib/libopenblasp-r0.3.28.so
        version: 0.3.27.dev
threading_layer: pthreads
   architecture: Haswell

       user_api: openmp
   internal_api: openmp
    num_threads: 12
         prefix: libgomp
       filepath: /home/lesteve/micromamba/lib/libgomp.so.1.0.0
        version: None
```

Labels: Bug, Needs Investigation