It is important for doctors to be clean so that they do not transmit infections. A white coat obviously shows the dirt and therefore gives confidence to the patient that their doctor is clean. It has also become a sort of uniform.
Lawyers wear black because it gives the impression that they are serious, professional and sober, inspiring confidence in their clients.