As far as I know you can’t animate the parent/child relationship itself, but you can animate the amount of influence a Copy Location/Copy Rotation/Copy Scale Constraint has, which is essentially the same thing as a parent child relationship. Just right click on the Influence slider and click insert keyframe.
The child moves because when you change “child of” influence, the child object keeps its locX, locY and locZ values but they are applied relative to another reference, from its parent’s reference to the world reference or the opposite.
Now If you want to avoid this problem you can use the “copy location” and “copy rotation” as described in the tread I gave.