He would not have to resign his position, merely recuse himself from that case. It happens at times and is the honorable way to keep from violating either of his oaths.
Well, in any case he needs to weigh whether a greater good can be achieved by violating the professional oath but putting a positive change into effect. For example, if an innocent life can be saved by the judge (or any other legal professional in the case) by breaking the law, recusing himself rather than saving that life is immoral. It is like jury nullification as applied to judges. Law is only as good as it is moral; upholding an unjust law is dishonorable.