What is opposite of transform.SetParent?

transform.SetParent sets the parent of the transform. What if I want to remove it from that parent and set its position and rotation to the last frame when it was the child of that parent.

I want an object to move around with camera (by making it the child of camera using SetParent) but at certain condition I want to stop it there (No more moving around with camera). When condition goes false again, it becomes the child of camera again and start moving with it. And so on…

Set a new parent for it to be a child of, or a null parent for it to be a child of the scene