Let's think about solving an equation for a second. When presented an equation like $3x + 7 = 22$ to solve, you are given two expressions representing numbers, $3x + 7$ and $22$, and told they are the same. You don't know which number $x$ is yet, but whatever it is, it will make $3x + 7$ the same as $22$.
To solve this equation, you can perform whatever numerical operation on the left side that you want, so long as you do the same on the right. You can perform any operation that deals in numbers, e.g. you can add $4$, multiply by $-17$, take both sides to the power of $9$, etc. Any operation that does something to a number, you can do to both sides, and the numbers you get as a result, will still be the same.
Differentiation does not operate on numbers, it operates on functions. When you take the derivative of $x^2 - 5x + 6$ at, say, $x = 1$, you don't just take into account the value of $x^2 - 5x + 6$ at $x = 1$ (which is $2$), you take into account the value at $x = 1$ and all the values around $x = 1$. We can't just replace $x^2 - 5x + 6$ with the number $2$, and differentiate. Even though they are the same number when $x = 1$, differentiation treats $x^2 - 5x + 6$ not as a number, but as a function.
The equation $x^2 - 5x + 6 = 0$ is not saying that $x^2 - 5x + 6$ is the same function as the constant $0$, it's saying that, whatever number $x$ may be, the number $x^2 - 5x + 6$ happens to be $0$. There will be many potential values of $x$ where $x^2 - 5x + 6$ is not $0$. So we should treat these quantities as numbers, not functions. We can perform any numerical operation we want to both sides, and maintain equality. As functions, $x^2 - 5x + 6$ is not the same as $0$, so taking the derivative of both sides has no guarantee to it will produce equal functions.
As an example to contrast, take the identity $\cos^2(x) = 1 - \sin^2(x)$. This is not just an equality between numbers, but it is an identity, i.e. an equality between functions. This is true for every number $x$. Since the two functions are the same, it is legitimate to differentiate both sides:
$$2\cos(x) \cdot (-\sin(x)) = 0 - 2\sin(x) \cdot \cos(x).$$
Note that, because we started with two functions that were the same, and applied the same operation on functions to both sides, we once a gain get two functions that are the same.
In short: you can apply differentiation both sides when dealing with an identity. If you need to find the few points $x$ that satisfy the equation, then you are not dealing with an identity, and you cannot perform differentiation.