How are the weights retained for filters for a particular class in a CNN?
Besides the last layer rest of the weights are shared among all classes. When an image is passed to the network all weights are updated accordingly. The only weights that are directly responsible for one specific class are the ones of the final layer. The rest of the weights are updated to find the best values to minimize the average loss for all classes.

To rephrase there aren't "filters" in convolutional layers that are specific for a single class. They are used to extract features so that the final layer can make the final prediction (which has weights for each specific class).

I'd suggest you look a bit into how gradient descent and backpropagation works.