Someone can give a more detailed explanation, but in short, there is an international agency (may be IATA, but not sure of that) that assigns the codes for each airline worldwide. SW was already in use so Southwest got WN. I don't know if there was any special (secondary) logic for that or if it was random.
USAir at one time had the AL code from Allegeny. As I recall, another carrier had the US code, although that wasn't necessarily their logical code. When their logical code became available, they dopped US and USAir got it.