The important thing is that the bandwidth is setup before the sample rate divisor.
// Digital low-pass filter and scale
// set this before sample rate else sample rate calculation will fail
// Sample rate
if (PIOS_MPU_SetSampleRate(cfg->default_samplerate, cfg->gyro_bandwidth) != 0)
Most of the cleanup I did removes duplicated code and centralizes the setting definitions. The change that makes it all work is setting the internal rate based on the dlpf setting, it's set at 1000 unless the dlpf is 256 Hz, in which case internal rate is set at 8000. Note that this internal rate refers to the MPU internal sample rate.
if (gyro_bandwidth < 256)
internal_rate = 1000;
internal_rate = 8000;
This makes the sample rate divisor calculate correctly regardless of the dlpf setting.
As to why it's like this, I don't know. The original authors chose, for one reason or another, to limit the dlpf settings to those which used the 1000 Hz internal sample rate. There were clearly some concerns about aliasing from the comments, which I've ignored in this experiment.