What is the purpose of 'oversampling' when the test set is still unbalanced?
Could someone please explain why do we use oversampling when both
  training and testing sets need to have the same distribution?


We use it because train and test set does not have to have the same distribution of labels. What is important is that the test set comes from the same distribution as your "real" data so that it provides a reliable measure. Post split the training set can be sampled as you see fit, as long as the results are good on your test set.