Before refrigeration butter would often spoil due to bacterial contamination. Salt was then added as a preservative. It works by dehydrating bacteria. Obviously since salted butter lasted longer, it could be produced more cheaply. Today, the salt is added only for flavor because bacterial spoilage is rarely a problem due to refrigeration. But the price differential has survived.