This is a great little prelude that ends completely unexpected, on the dominant of D minor rather than the tonic of F major. There are reasons behind this, though. From Raymond Nagen's blog on the Orgelbuchlein: "Didn’t this piece begin in F? Is this some sort of Mahlerian progressive tonality, two centuries before its time? To figure out what’s going on here, we have to take a closer look at the original melody. “Lob sei dem allmächtigen Gott” is one of the types of chorales mentioned in yesterday’s post – it’s adapted from an older Gregorian chant, “Conditor alme siderum“. Both melodies, it turns out, are actually not in F major, but in the Phrygian mode. In other words, they center around A (even though the chorale, unlike the chant, does begin on F). And in the Phrygian mode, the second scale degree is flattened. This means that there isn’t a normal second scale degree (B-natural) – it doesn’t exist in the mode – and therefore there’s no way of making a normal V–I cadence. The best solution for ending a piece in Phrygian is this, the so-called “Phrygian cadence,” which is exactly what Bach does. Now, the interesting conclusion to draw from this digression into music theory is that Bach sincerely wished to maintain the modal character of this Phrygian melody, so much so that he insisted on writing this strange, archaic ending to his prelude. Bach learned how to use the eight church modes as part of his basic musical training, and for his whole career he was able to use modality alongside tonality. There was no need for one system to supplant the other.
"This speaks to something deeply important about Bach’s character – he made a great effort to preserve the old, traditional ways he inherited. (We’ll see another significant example as we continue looking through the Orgelbüchlein preludes.) For Bach and other composers of his generation, tonality and modality existed side-by-side, and could be used in different situations and for different purposes."
Ah Bach. Being playful