Given a function $f : X \rightarrow Y$, it is well-known that we can take the image under $f$ of any subset $A \subseteq X$, and we can take the preimage under $f$ of any subset $A \subseteq Y$. This is fundamental.
A little less well-known is that we can take the preimage under $f$ of an equivalence relation $\cong$ on $Y$. In particular, we define $f^{-1}(\cong)$ to be the unique equivalence relation $\sim$ on $X$ such that the following holds.
$$x \sim x' \iff f(x) \cong f(x')$$
It is easy to verify that this is indeed an equivalence relation.
Question. If $f : X \rightarrow Y$ is an arbitrary function (so that, in particular, we're not assuming that $f$ is surjective), is it the case that to every equivalence relation $\sim$ on $X$, there is a naturally corresponding equivalence relation $f(\sim)$ on $Y$?
Basically, I can see at least two possible ways of doing this. In one approach, every two elements in $Y \setminus f(X)$ is equivalent; in the other, no two distinct elements in $Y \setminus f(X)$ are equivalent.
But how do we know which is the "correct" definition?
Here is one way you can pushforward an equivalence relation. If you have any relation $\sim$ on a set $X$, you can think of $\sim$ as a certain subset $R \subset X \times X$. Then $R$ is an equivalence relation if it satisfying the following three conditions:
This is just a restatement of the usual definition of equivalence relation. Now, if we have a function $f:X \to Y$, we get an induced function $F:X \times X \to Y \times Y$ given by $F(x,x') = (f(x),f(x'))$. Then, given a relation $R \subset Y \times Y$, we get an relation on $X$ by literally taking the preimage $F^{-1}(R) \subset X \times X$. By definition, $(x,x') \in F^{-1}(R)$ if and only if $(f(x),f(x')) \in R$ so it's clear this is exactly the pullback you described in your question. You can verify that if $R$ is an equivalence relation then $F^{-1}(R)$ will also be an equivalence relation. In this way we get a well defined way to pullback equivalence relations along $f$. Let's denote this $f^*(\sim)$ since we're really taking the preimage by $F$ not $f$.
Now that we've found a way to restate pulback of equivalence relations, how can we use this same $F$ to pushforward equivalence relations? The obvious thing to do is say that if $R \subset X \times X$ is a relation on $X$, then define the pushforward $f_*(\sim)$ by $F(R) \subset Y \times Y$. This is a fine relation. However, when we try to check if $F(R)$ is an equivalence relation when $R$ is, we run into trouble and find that it's not. So the question is what is the simplest or most "universal" way to turn $F(R)$ into an equivalence relation?
Well we know we're looking for some equivalence relation $R' \subset Y \times Y$ such that $F(R) \subset R'$ because we want the equivalence relation $R'$ to still satisfy the relation of $F(R)$. But we don't want to change too much, we want to change $F(R)$ as little as possible while making it an equivalence relation, otherwise we can take something stupid like $R' = Y \times Y$. So in some sense we again do the "obvious" thing and take $R'$ to be the smallest equivalence relation still containing $F(R)$. This is well defined because you can check that the intersection of equivalence relations is an equivalence relation. Then we can define the $f_*(\sim)$ to be the equivalence relation given by $R'$.
Really we could make this construction for any relation $S$ and take the smallest equivalence relation containing $S$ and call it the "equivalence relation generated by $S$" or maybe the "equivalencication" of $S$. Let's call this $S^\sim$ Explicitly this means taking the relation $S$, adding $(y,x)$ whenever $(x,y) \in S$ (the symmetric closure), adding $(x,x)$ for every $x$ (reflexive closure), and adding $(x,y)$ whenever there is a chain of related elements as in Martin Brandenburg's answer (the transitive closure). For this specific case, it is already symmetric but we do need to take the reflexive and transitive closure.
To address Paul's question in the comments, this construction gives us a way to compose pushforwards and pullbacks of relations. It is functorial. Specifically, if we have $f:X \to Y$ and $g:Y \to Z$, let $F$ as above and $G:Y \times Y \to Z \times Z$ given by $G(y,y') = (g(y),g(y'))$. Then the pullback of an equivalence relation $\sim$ on $Z$ given by $R \subset Z \times Z$ clearly satisfies $f^*g^*(\sim) = (gf)^*(\sim)$ since $F^{-1}G^{-1} = (GF)^{-1}$.
For the pushforward, it is less obvious. If $\sim$ is an equivalence relation on $X$ corresponding to $R \subset X \times X$, $g_*f_*(\sim) = (gf)_*(\sim)$ if and only if $(G\circ F)(R)^\sim = G(F(R)^\sim)^\sim$ which isn't too hard to check.
This actually fits into a general picture in math that happens quite often. What we really have here is in categorical terms an adjunction. We have the category $\mathcal{R}$ of relations on $X$ and the subcategory $\mathcal{EqR}$ of equivalence relations along with the forgetful functor $G: \mathcal{EqR} \to \mathcal{R}$ that just views an equivalence relation as a normal relation. Then the "equivalencication" above is the left adjoint of $G$. We have the obvious functorial pullback and pushforward of relations given by $F^{-1}(R)$ and $F(R)$ above and the we use the adjunction to define functorial pullbacks and pushfowards $f^*$ and $f_*$ on equivalence relations.
Sorry this answer is so long, I was on a plane with no internet and already had this page open so figured I could type a really in depth answer!