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:
### Describe the bug

Hi, I updated my packages to both the last version and to your version.  I can confirm that, in this cases, the example does not present any error. However, I still have issues in my complete code with updated packages. I created a new minimum example where this happens with new packages.  

In particular:
1 - I expect that the ordering of neighbors does not depend on the algorithm but on the ordering of training data - i.e. first and second line of the print to be equal
2 -  I expect that the ordering of neighbors depends on the ordering of training data - i.e., the first element of the first line should be 78 (it has the same distance of 88), and the last two elements of the third should be in a different order. Such behavior is indeed correct in the case of the second line.

### 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 KNeighborsClassifier

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]
y_train = y_train[0:100]
x_test = x_test[8:9]

ml1 = KNeighborsClassifier(n_neighbors=5, algorithm='kd_tree').fit(x_train, y_train)
d1,n1 =  ml1.kneighbors(x_test, return_distance=True)

auto_ml = KNeighborsClassifier(n_neighbors=5 ).fit(x_train, y_train)
auto_d, auto_n =  auto_ml.kneighbors(x_test, return_distance=True)



ml2 = KNeighborsClassifier(n_neighbors=6, algorithm='kd_tree').fit(x_train, y_train)
d2,n2 =  ml2.kneighbors(x_test, return_distance=True)

print(n1)
print(auto_n)
print(n2)

print(d1)
print(auto_d)
print(d2)
```


### Expected Results

``` 
[[43 38 83 52 78]]
[[43 38 83 52 78]]
[[43 38 83 52 78 88]]
[[1.41421356 1.73205081 2.23606798 2.44948974 2.82842712]]
[[1.41421356 1.73205081 2.23606798 2.44948974 2.82842712]]
[[1.41421356 1.73205081 2.23606798 2.44948974 2.82842712 2.82842712]]

```

### Actual Results


``` 
[[43 38 83 52 88]]
[[43 38 83 52 78]]
[[43 38 83 52 88 78]]
[[1.41421356 1.73205081 2.23606798 2.44948974 2.82842712]]
[[1.41421356 1.73205081 2.23606798 2.44948974 2.82842712]]
[[1.41421356 1.73205081 2.23606798 2.44948974 2.82842712 2.82842712]]

```

### 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\.venv\Scripts\python.exe
   machine: Windows-10-10.0.19045-SP0

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: 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: libscipy_openblas
       filepath: C:\Users\Corrado\OneDrive - Politecnico di Torino\Corrado\Politobox\Research\repository\scalabaleLearning\.venv\Lib\site-packages\numpy.libs\libscipy_openblas64_-c16e4918366c6bc1f1cd71e28ca36fc0.dll
        version: 0.3.27
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\.venv\Lib\site-packages\sklearn\.libs\vcomp140.dll
        version: None

       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\.venv\Lib\site-packages\scipy.libs\libscipy_openblas-5b1ec8b915dfb81d11cebc0788069d2d.dll
        version: 0.3.27.dev
threading_layer: pthreads
   architecture: SkylakeX


```

Labels: Bug, Needs Investigation