All we are doing is: the following equation holds for every $x \in \mathbb{R}-\{2\}$:
\begin{equation*}
\frac{x^2-4}{x-2}=x+2
\end{equation*}
We exclude the case $x=2$ because the left side is undefined when $x=2$ so that, when thinking the left side as a function we exclude $2$ from its domain.
More details:
When we define a function, three things must be specified: the domain, the codomain, and the rule which the function uses to associate each element in the domain an element in the codomain.
If $F$ and $G$ are functions, we write $F=G$ to express the meaning "$F$ and $G$ are the same function". That is:
- $F$ and $G$ have the same domain.
- $F$ and $G$ have the same codomain.
- For each $x$ belonging to the domain, $F(x)=G(x)$.
When people write an expression in format $f(x)=$ something, where something involves a polynomial, a quotient, an exponential, or any other things that makes sense when $x$ is a real number, without specifying anything, we tacitly assume:
- $f$ is a function.
- The domain of $f$ is whatever subset of the real line such that the expression "something" is well-defined.
- The codomain of $f$ is the real line.
- If $x$ belongs to the domain, then $f(x)$ is given by this "something".
Now, as an example, we go back to your question. When we write $f(x)=x^2-4$, what we mean, tacitly, is that we define a function $f:\mathbb{R} \to \mathbb{R}$ by setting $f(x)=x^2-4$ for every $x \in \mathbb{R}$ simply because the expression makes sense for every $x \in \mathbb{R}$. Similarly, when we write $g(x)=x-2$, we mean that we define a function $g:\mathbb{R} \to \mathbb{R}$ by setting $g(x)=x-2$ for every $x \in \mathbb{R}$. By writing $y=\frac{f(x)}{g(x)}=\frac{x^2-4}{x-2}$, we mean that we define a function $y: \mathbb{R}-\{2\}\to \mathbb{R}$ by setting $y(x)=\frac{x^2-4}{x-2}$ for every $x \neq 2$, simply because the expression makes sense for every $x \neq 2$.
Now, if we define a function $z: \mathbb{R} \to \mathbb{R}$ by setting $z(x)=x+2$, then we may write $z \neq y$ because their domain is different.
Although one may remark that $z(x)=y(x)$ for every $x \neq 2$, this is irrelevant to our current dicussion about equality between functions. (But as pointed out in the comment, since the domain of $y$ is a subset of the domain of $z$, sometimes people still write $z=y$ to express the above remark. This is not standard.)
Finally, by the graph of a function $F:A \to B$, we mean the set $\{(a,F(a))\}_{a\in A}\subseteq A\times B$. If we use $Y$ to denote the graph of $y$ and $Z$ for graph of $z$, then the remark shows that $Y$ and $Z$ differ by exactly one point, namely the point $(2,4) \in \mathbb{R}^2$.