In the equation: $\frac{z^2-1}{z-1}$ $z$ can not be equal to $1$.
However $\begin{align} \frac{z^2-1}{z-1}&=\frac{(z-1)(z+1)}{z-1}\\ &=(z+1) \end{align}$ So then if $z$ is equal to $1$ we have $\frac{z^2-1}{z-1}=2$
Can someone explain that please?
In the equation: $\frac{z^2-1}{z-1}$ $z$ can not be equal to $1$.
However $\begin{align} \frac{z^2-1}{z-1}&=\frac{(z-1)(z+1)}{z-1}\\ &=(z+1) \end{align}$ So then if $z$ is equal to $1$ we have $\frac{z^2-1}{z-1}=2$
Can someone explain that please?
Algebraists will talk about things like $\mathbb C(z)$, the "field of rational functions over $\mathbb C$", and in that field it is indeed the case that $\frac{z^2-1}{z-1} = z+1$, but this doesn't say anything about being able to evaluate the function defined by $f(z) = \frac{z^2-1}{z-1}$ at $1$. What it does say is that $z^2-1 = (z-1)(z+1)$.
Let $f(z) = \frac{z^2-1}{z-1}$ and $g(z) = z+1$ then $f$ is analytic on $\mathbb C \setminus \{1\}$ and $g$ on $\mathbb C$.
A theorem of complex analysis says that if two functions coincide on an open set then they are equal everywhere that they are both defined.
This implies that there is a unique way to continue a function (such as $f$) onto a larger domain if it shares some overlap with another function (such as $g$).
This justifies continuing $f$ to a function on the whole of $\mathbb C$ by defining $f(1) = 2$.
This step $\begin{align} \frac{(z-1)(z+1)}{(z-1)}&=z+1 \end{align} $ is only valid when $z \not=1$.
The point at $z = 1$ is called a "removable singularity", and this process "removes" it. In general, a function having a limit at a point but not defined there can be extended to a function continuous at that point in only one way. That's what happens here. $\frac{z^2 - 1}{z - 1}$ is defined and continuous everywhere except $z = 1$, and has a limit at $z = 1$. $z + 1$ is defined and continuous everywhere, and equals $\frac{z^2 - 1}{z - 1}$ wherever both are defined. So then it must be that unique extension.
NB: It's worth noting that as other posters have pointed out, this equation is not technically correct since one expression is undefined at the point and the other isn't, but the procedure you used gives the unique extension just mentioned.
Rather than making a statement like \begin{align*} \frac{z^2 - 1}{z-1} = z + 1 \end{align*} without saying what $z$ is, you should make a more careful statement like this:
If $z \in \mathbb{R}$ and $z \neq 1$, then $\frac{z^2 - 1}{z - 1} = z + 1$.
It wouldn't make sense to plug in $z = 1$, because that equation is not even true if $z = 1$.
In this case $z = 1$ is a hole!
In this type of case, for any value of z other than 1, the terms will cancel out and the function will behave like z+1. Notice that when z=1, the function is undefined. That means that that value can't be in the domain. We call it a hole.
To try and understand why you still cannot divide by 0 even in cases like this, try to graph out the function $f(x) = \frac{1}{x}$ and plug in values near 0 from the left and the right. Try values in this interval $0 \leq x \leq 1$ and notice what happens as you get closer to 0. After you check this by hand, go to wolfram or your calculator and look at what happens to verify. I hope this helps.
By writing $z-1$ in the denominator you are already implicitly assumthat $z≠1$. Even if you derive the expression $z+1$ or anything else from the previous one, the assumption still holds that $z≠1$.
What you showed above holds if and only if $z≠1$. Conversely, if $z=1$ it does not hold. In the case that $z=1$, the expression $\frac{z^{2}-1}{z-1}$ is undefined, so it cannot be reduced to anything.