First I'll characterize those finite metric spaces with well-defined metric dimension in terms of the purity of a related simplicial complex and then briefly talk about how matroids fit into the picture.
Simplicial Complex Background
We will need some terminology for (abstract) simplicial complexes. A simplicial complex on a set $S$ is a collection of subsets $\Delta$ of $S$ that is closed under taking subsets, that is, if $T \in \Delta$ and $T' \subseteq T$, then $T' \in \Delta$. The elements of $\Delta$ are called its faces and the inclusion-maximal faces are the facets of $\Delta$. The rank of a face $F$ is given by $r(F)=\#F$ and the rank of $\Delta$, denoted $r(\Delta)$, is the largest rank of a face in $\Delta$.
Note that for a general simplicial complex, the cardinality of two facets need not be equal. (Example: $([3], \{\emptyset, 1, 2, 3, 23\})$.) However, if all facets do have the same cardinality the simplicial complex is called pure.
A (nearly trivial) characterization
Let $(M,d)$ be a finite metric space and let $\mathcal{G}$ be the collection of all generating sets for $(M,d)$. Define the set
$$\Delta = \Delta(M,d) := \{M \setminus G~|~G \in \mathcal{G}\}.$$
Note that if $G' \supseteq G$ and $G \in \mathcal{G}$ then $G' \in \mathcal{G}$. This impies that the set $\Delta$ is an abstract simplicial complex on $M$. The facets of $\Delta$ correspond to cardinality-minimal generating sets of $(M,d)$ by set complementation. So the metric dimension of the finite metric space $(M,d)$ is well-defined if and only if the complex $\Delta(M,d)$ is pure. In this case, $\dim(M,d) = \#M - r(\Delta)$.
Matroids
Now let me try to tie this into the matroid discussion in Example 1 of this answer to the previous question. In that example we have $M = \{0,1,2,3\}$ and $d$ given by
$$d(x,y) = \begin{cases} 2 \text{ if } x,y \neq 0 \\ 2 + \frac{1}{y} \text{ if } x = 0. \end{cases}$$
One computes that $\mathcal{G}$ is all subsets of $\{0,1,2,3\}$ except for the empty set and the singletons $\{i\}$ where $i \in [3]$. So $\Delta(M,d)$ is the simplicial complex
consisting of all subsets of {0,1,2,3} that do not contain 0
whose faces are arranged by containment in the following poset. So $\Delta(M,d)$ is not pure (it has three facets of rank two and a facet of rank three) and so the metric dimension for $\Delta(M,d)$ is not well-defined.
For an arbitrary finite metric space $(M,d)$, the complex $\Delta(M,d)$ is a matroid (that is, its facets satisfy the basis exchange axiom for matroids) if and only if the "matroid dual" complex
$$\Delta^*(M,d) := \{H \subseteq G | G \text{ is inclusion-minimal in } \mathcal{G}\}$$
is a matroid. In this case the metric dimension of $(M,d)$ is just the rank of $\Delta^*(M,d)$.