When deriving the magnetic field inside of an infinitely long solenoid carrying a stationary current, it's useful to take into consideration the symmetries of the problem, in order to understand which components the field actually has and on which variables it depends.
Considering cylindrical coordinates, and placing the $z$ axis so that it passes through the solenoid's center and it is perpendicular to the loops, we can say that the field doesn't depend on $\theta$ because there is a rotation symmetry around the z axis, and it doesn't depend on $z$ either, because there is a translation symmetry along the $z$ axis, so it depends on $r$ only.
Since there isn't a parity symmetry, if we put the solenoid upside down, a potential $r$ component of the field would remain the same, although the system isn't equal to the first one, because the current would flow in the opposite verse. Therefore, there can't be an $r$ component.
What I don't understand is why we can assume that there isn't a $\theta$ component either, and therefore compute the field assuming that it only has a $z$ component.