Pigs love mud, and the reason has to do with sweating.
"All animals keep cool, but some animals keep cooler than others," one of Animal Farm's politicians might be heard to grunt.
Like all warm-blooded mammals, swine (to be precise, "pig" refers solely to young swine) need to maintain a balanced body temperature. For many mammals, humans included, sweating is a useful way of keeping off the heat. Sweat cools because the evaporation of water requires energy, and when we sweat that energy gets sapped from body heat.
Pigs do have a few sweat glands, but they're not very useful for temperature adjustment. When the mercury rises on the farm, Wilber wallows in cool water or mud, which has the same evaporation effect as sweating.