How can I protect my pigs so they don't become pigmen?
Lightning only strikes straight down, but can transform a pig within 3-4 blocks of the lightning strike. Therefore, to keep your pigs safe from lightning storms, their shed has to be built so that it keeps them at least 5 blocks away from the outside sky. Building a 5 block wide overhang around the shed roof should do it. Alternatively, make your barn so that the pigs are in an inner chamber, with less "volatile" livestock like chickens and cows in the chambers near the walls.