I would have to see your code to be sure, but it sounds like you left in one or more of the other rotates (rotateX or rotateY). If you want to only rotate around the Z axis, then the easy answer is to just remove those rotations.
If (instead) you want to rotate around Z and also around X or Y, then the order of the rotations is significant (matrix multiplication is not communities, so the order of operations does matter). My guess is that you probably want to rotate around Z first. If you rotate around X or Y first then when you rotate more than halfway around X or Y then the subsequent rotation around Z will appear to go in the wrong direction.
Play around with it. If you can’t get what you want, post your code and I’ll try to help.