Unable to compute AgglomerativeClustering with affinity 'precomputed' and linkage 'ward'

### Describe the bug

When trying to compute AgglomerativeClustering with affinity='precomputed', linkage='ward' I get the following error:

`ValueError: precomputed was provided as affinity. Ward can only work with euclidean distances.`
I think this is intended. What is the reason behind it?

### Steps/Code to Reproduce

```
from sklearn.cluster import AgglomerativeClustering
from sklearn.metrics.pairwise import euclidean_distances
import numpy as np

X = np.random.normal(size=(2,4))
dist=euclidean_distances(X)
cluster_dist = AgglomerativeClustering(n_clusters=2, affinity='precomputed', linkage='ward')
results_dist = cluster_dist.fit(dist)
```

### Expected Results

The resulting clusters

### Actual Results

```
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [122], in <module>
      2 dist=euclidean_distances(X)
      3 cluster_dist = AgglomerativeClustering(n_clusters=n_cluster, affinity='precomputed', linkage='ward')
----> 4 results_dist = cluster_dist.fit(dist)

File ~/Documents/technical/xai_cats_dogs/xai_cats_dogs_venv/lib/python3.9/site-packages/sklearn/cluster/_agglomerative.py:918, in AgglomerativeClustering.fit(self, X, y)
    900 """Fit the hierarchical clustering from features, or distance matrix.
    901 
    902 Parameters
   (...)
    915     Returns the fitted instance.
    916 """
    917 X = self._validate_data(X, ensure_min_samples=2, estimator=self)
--> 918 return self._fit(X)

File ~/Documents/technical/xai_cats_dogs/xai_cats_dogs_venv/lib/python3.9/site-packages/sklearn/cluster/_agglomerative.py:955, in AgglomerativeClustering._fit(self, X)
    950     raise ValueError(
    951         "compute_full_tree must be True if distance_threshold is set."
    952     )
    954 if self.linkage == "ward" and self.affinity != "euclidean":
--> 955     raise ValueError(
    956         "%s was provided as affinity. Ward can only "
    957         "work with euclidean distances." % (self.affinity,)
    958     )
    960 if self.linkage not in _TREE_BUILDERS:
    961     raise ValueError(
    962         "Unknown linkage type %s. Valid options are %s"
    963         % (self.linkage, _TREE_BUILDERS.keys())
    964     )

ValueError: precomputed was provided as affinity. Ward can only work with euclidean distances.
```

### Versions

```shell
System:
    python: 3.9.7 (default, Oct 13 2021, 06:45:31)  [Clang 13.0.0 (clang-1300.0.29.3)]
executable: /Users/cristianpachon/Documents/technical/xai_cats_dogs/xai_cats_dogs_venv/bin/python
   machine: macOS-11.4-x86_64-i386-64bit

Python dependencies:
          pip: 21.3.1
   setuptools: 60.5.0
      sklearn: 1.0.2
        numpy: 1.22.2
        scipy: 1.8.0
       Cython: None
       pandas: 1.4.1
   matplotlib: 3.5.1
       joblib: 1.1.0
threadpoolctl: 3.1.0

Built with OpenMP: True
```
```

COMMENT:
Thank you opening this issue!

According to our [triaging guidelines](https://scikit-learn.org/dev/developers/bug_triaging.html#triaging-operations-for-members-of-the-core-and-contributor-experience-teams), I am closing this issue because it is a duplicate of https://github.com/scikit-learn/scikit-learn/issues/15287. You are welcome to continue the discussion there.

Labels: Bug, module:cluster, Needs Triage