1. To help keep them cool in hot temperatures.
2. To create a barrier from insects. Can you blame them?
3. It's their version of SPF! Their hair is very coarse and you can see their skin underneath. Without their mud baths, they'd get sunburn.
I've read articles that state, they are not necessary and even unsanitary. After watching our pigs create their own, I believe its ingrained. Similar to hand raising chicks; how do they know to scratch for food or dust bath if they've never been around a full grown hen? They just know.
We dug out a specific wallow area for them and fill it with fresh water almost every day, unless it rains. It naturally drains or soaks into the ground making it necessary. As soon as the water gets turned on, they all make a dash for their wallow.