Why does differentiating $-\frac{2}{x+1}$ or $\frac{2x}{x+1}$ result in the same function $\frac{2}{(x+1)^2}$?

Because their difference is constant:$$\frac{2x}{x+1}-\frac{-2}{x+1}=\frac{2x+2}{x+1}=2.$$Therefore,$$\left(\frac{2x}{x+1}-\frac{-2}{x+1}\right)'=0.$$


Don't forget that there should be a constant of integration, $C$, at the end of your answer that always differentiates to zero: $\int\frac{2}{(x+1)^2}\,dx=-\frac{2}{x+1}+C$. The integral of a function is not just one single function, but a whole family of infinitely many functions that differ only by a constant. And the second function is nothing more than the first function plus a $2$ (a constant):

$$ -\frac{2}{x+1}+2= -\frac{2}{x+1}+2\frac{x+1}{x+1}=\\ \frac{-2}{x+1}+\frac{2x+2}{x+1}= \frac{-2+2x+2}{x+1}=\\ \frac{2x}{x+1}. $$

Since they're the same function, their derivatives should be equal:

$$ \left(-\frac{2}{x+1}+2\right)'=\frac{2}{(x+1)^2}+0=\frac{2}{(x+1)^2}.\\ \left(\frac{2x}{x+1}\right)'=\frac{2}{(x+1)^2}. $$