No, it’s not necessary but it is recommended to choose law for the civil services exam if the candidate is from a similar background.