Nicki Minaj just beat her hairstylist’s ass in court after the judge wigged out.

Terrence Davidson had filed a $30 million lawsuit against Nicki … claiming he helped design her multi-colored wigs and she in turn agreed to partner with him on a new line of the iconic hairpieces but then cut him out.

But the judge sided with Nicki … dropping some serious wig knowledge in the process. The judge explained there’s nothing special about colored wigs … anyone has a right to make them so Davidson’s creative claim is bogus.

The judge called out 3 of Nicki’s wigs to illustrate his point … The Pink Upper Bun Wig, The Fox Fur Wig and the Pink High Top Wig.

The judge also said any so-called deal Davidson made with Nicki was vague — nothing more than barber shop talk.