This is most likely because when you affect a transform on a “child” object, they are changed in relation to the parent. Have you tried altering your system to either unparent the object, or altered your code to ensure the object is rotating with actual respect to your current object? Also, have you tried using the object animator for this? It might give you a better way to do what you are trying.
If you have any more actual information here, it might be helpful to share. I’m not even sure what you are wanting exactly, and you need to tell us how it is operating incorrectly before the problem can be fixed. Is it rotating the wrong way or not at all? Does the child object HAVE to be attached to the parent object for your script to work (like something floating over the parent object and rotating, or does it just need to rotate as a general rule?)