How to limit a GameObject's angle?

Hi, i am trying limit a GameObjet’s angle on z axis.There are two objects, A and B. B is a parent of A and A has a rotation code like the following;

A.Rotate(0, 0, 1);

Since B is a parent of A it also gets rotated as A does but i do not actually see a change in B’s angles in the editor?My first question regarding to this is why? And my second question is that how do i limit the angle of B on z axis but A keeps rotating itself.Note that B becomes a parent of A when a statement becomes true, like the following;

if(bla bla == true)
{
     B.parent = A.transform;
}
else
{
     B.parent = null;
}

Could anyone give me a comment about these questions?

If you are using rigidbody for your gameobject, check on freeze rotaion on z-axis