Let $A$ be a set. Define $d(x,A) = \inf \{d(x,a)| a \in A \}$. So for any $a$, $d(x,A)\leq d(x,a)$ and for any other $r \leq d(x,a)$ we have $r \leq d(x,A)$. Now let $x$ and $y$ be two different points and suppose $d(y,a) \leq d(x,a)$. I mistakenly concluded that $d(y,a) \leq d(x,A)$ since $d(y,a)$ is just some number in $\mathbb{R}$. But $x=0,y=1,A=(1,\infty]$ is a counter example.
For me at least, this is such an easy mistake to overlook and I feel kind of stupid for making it. My question is how can mistakes like this be avoided? The only way I thought of is to write it out in first order logic. Formally what we are saying is suppose $\exists x \exists y \forall a \ d(y,a) \leq d(x,a)$ or equivalently $ \forall a \exists x \exists y \ d(y,a) \leq d(x,a)$. I know that $\exists x$ after $\forall a$ intuitively means that $x$ is a function of $a$ (and analogously $y$ is a function of $a$?). But how to make use of this to avoid the mistake?
Another thought I had was to treat the whole sentence as a function of $a$, so that although $d(y,a) \leq d(x,A)$ is an invalid conclusion, $d(y,A) \leq d(x,A)$ would be correct since it would be like substituting the value $A$ for $a$. Or would we separately have to conclude $d(y,A) \leq d(x,a)$ and then $d(y,A) \leq d(x,A)$? The first being valid because it is not trying to squeeze a value in between, unlike $d(x,A)$, and the second being valid because now the left side doesn't depend on $a$.
The key here is to remember what's fixed and what varies in what you care about; $d(x,A) = \inf \{d(x,a)| a \in A \}$, here $a$ is what is changing and x is fixed. So if you're comparing $d(x,a)$ and $d(y,a)$ although what is written seems to suggest that $x$ and $y$ are the variables, to avoid confusion just simply refer back to you definition and notice that $a$ is what is being varied.
A suggestion to avoid confusion: maybe give other names to your points $x$ and $y$ since, traditionally, $x$ and $y$ are variables. If I had this sort of difficulties, maybe I would name my points $a$ and $b$ or $m$ and $n$ since these letters usually refer to some constant rather than a variable.
Regarding what you said at the end of your question, your conclusion is not quite correct given what you shared in your question. If, indeed, $\forall a \ d(y,a) \leq d(x,a)$ then yes $d(y,A) \leq d(x,A)$ because of the fact that $\forall a \ d(y,a) \leq d(x,a)$ implies that $\exists a_0 \ d(y,a_0) \leq d(x,A)$ and since $\forall a \ d(y,A) \leq d(y,a) $ then we get the desired result $d(y,A) \leq d(x,A)$.