Wikipedia while deriving Bertrands theorem writes after some steps:
...For the orbits to be closed, $β$ must be a rational number. What's more, it must be the same rational number for all radii, since $β$ cannot change continuously. Using the definition of $J$ along with equation (1) we get
$J^{\prime}\left(u_{0}\right)=\frac{2}{u_{0}}\left[\frac{m}{L^{2} u_{0}^{2}} f\left(\frac{1}{u_{0}}\right)\right]-\left[\frac{m}{L^{2} u_{0}^{2}} f\left(\frac{1}{u_{0}}\right)\right] \frac{1}{f\left(\frac{1}{u_{0}}\right)} \frac{d}{d u_{0}} f\left(\frac{1}{u_{0}}\right)=-2+\frac{u_{0}}{f\left(\frac{1}{v_{0}}\right)} \frac{d}{d u_{0}} f\left(\frac{1}{u_{0}}\right)=1-\beta^{2}$
where $J^{\prime}\left(u_{0}\right)=\left.\frac{d J}{d u}\right|_{u_{0}}$
Since this must hold for any value of $u_0$ then ${\displaystyle {\frac {df}{dr}}=(\beta ^{2}-3){\frac {f}{r}}}$ and hence ${\displaystyle f(r)=-{\frac {k}{r^{3-\beta ^{2}}}}.}$
and then we find that ${\displaystyle J(u)={\frac {mk}{L^{2}}}u^{1-\beta ^{2}}.}$
However by a similar argument we can say that since $β$ is a constant then we can directly solve $J^{\prime}(u)=1-\beta^{2}$ and find that $J=\left(1-β^{2}\right) u$ which is wrong.
Were did I go wrong.
Link:https://en.wikipedia.org/wiki/Bertrand%27s_theorem#math_2