The optimizer will update all passed parameters.
However, the optimizer does not define how the gradients are being calculated.
The computation graph is defined during your forward pass. If you call .backward() on the loss (or any other tensor), the Autograd will backpropagate using the computation graph to calculate the gradients.
E.g. if you calculate the loss using the output of Classifier B, loss.backward() will calculate the gradients of the parameters in Classifier B as well as Encoder A (, since Classifier A was never touched to calculate this particular loss).