It has to do with the way many lords aquired land in the middle-ages. They often didn't conquer neighbouring territories. Instead they tactically married to eachother to combine the family and the realm which was owned by the families. And the lands of the marying families didn't have to be right next to each other. They could be hunderds of miles away. But they would become part of the same nation. The german states before the unification of germany is a prime example of what a mess such states can become