WeightedRandomSampler is a custom sampler, which draws the samples from your Dataset given the specified weights and can be used to over- or undersample the dataset.
A class weighting can be enabled via the weight argument in the criterion (e.g. nn.CrossEntropyLoss) and would apply the class weights to the loss calculation.
Both approaches can be used to counter the effects of an imbalanced dataset, but are different in their workflow.