It is not z to be considered, but z25, which is a free parameter that plays the role of $n$ in your own solution. Note that free variables are generated on demand, so if you run the same solve command at the beginning of a Sage session, you will get z1.
sage: solve(sin(x)-cos(x) == 0, x, to_poly_solve=True)[0].variables()