It's done to prevent rotation. Milling off the flat sides of the thread is easy. And you must remember that the vast majority of devices aren't made by hand, they're mass-produced. In a plastic or die-cast metal enclosure you just mold the right shape hole to begin with. In sheet metal cases, the holes are punched as part of the stamping process for the sheet metal parts. And in modern CNC milled or laser-cut stuff, the CNC or laser takes care of it.
They are a PITA for prototyping. Yeah, you basically drill undersize and then file away at it. You don't need a "special" file, just a curved file with a reasonably appropriate width and curvature.
When possible, I try to find switches, potentiometers, and connectors that use alternative methods to prevent rotation, like an orientation pin or notch that is outside the main hole. Then you can just use a small file to file a notch for it, or a small drill to make a second hole, as the design requires.
There do exist, for some connectors/switches/pots, adapter washers that are punched with the flattened hole, and then have a pin to locate in an anti-rotation hole as above.