In Britain both lawyers and judges can still wear wigs as well as robes. In British Columbia, we do not wear wigs, and starting November 2021 we no longer address BC Supreme Court justices with the traditional My Lord or My Lady. There is a helpful summary on the Provincial Court website at https://www.provincialcourt.bc.ca/enews/enews-11-09-2018 about the history of judicial robes, and a summary of the history of judicial wigs on the web
Like any uniform, the use of robes and wigs started in the 17th century as early as 1625 so the public could recognize judges and lawyers. The public stopped wearing wigs but wigs are still worn today by British barristers. In Canada, wigs are only worn by the SCC for ceremonial events and usually not by anyone else eg in 1905 BC banned them.
Quoting from the Provincial Court article: "...judges’ robes are a tradition – one they maintained long after styles changed and other segments of society embraced different fashions. But it’s a tradition that serves a purpose today. Judges’ robes lend dignity to judicial proceedings, distinguish independent courts from other decision-making tribunals, and remind people of the important role our courts play in a democratic society - resolving disputes peacefully and fairly, and upholding our constitution and the rule of law."
Now lawyers and judges usually wear robes only for Supreme Court trials, while only judges not lawyers wear robes in Provincial Court.