It’s because the Editor is a managed application that performs a bunch of tasks while you’re playing your game and produces garbage etc.
cam.transform.position = new Vector3(transform.position.x + cameraDistance,
cam.transform.position.y, cam.transform.position.z);
The above code only moves the camera each fixed-update; you’d want to do that per-frame. If you set the Rigidbody2D to use interpolation then it’ll update the Transform position/rotation per-frame; you can track the Transform during the Update.