The courtroom wig actually dates from an era centuries ago when it was common for the upper classes to shave their heads and wear wigs - a practice that arose for hygiene reasons.
That is, at the time when this practice first arose in courtrooms, such wig-wearing simply reflected an ordinary style of dress.
The practice dates from the 16th and 17th centuries.
What happened since is that styles of appearance in wider society have moved on, but not amongst lawyers in the courtroom, and in the modern day such wigs have become characteristic of courtroom dress.
Until the mid-Victorian era, such sartorial traditions were the least of the anachronisms carried forward from earlier centuries.
There have been some reforms in recent decades that limit the archaic appearance of judges, but one of the argument for courtroom dress has always been to make the proceedings seem solemn and formal, and to depersonalise the appearance of those who participate as officers of the court.