There are two primary muscle groups at work. The ones which control the 2 larger fingers, the 1st and 2nd phalanges (thumb and index) are controlled with the larger thenar muscles, called the flexor pollicis brevis, abductor pollicis brevis, and opponens pollicis muscles - collectively, I'll call them the thenar muscles.
The 3rd, 4th, and 5th phalanges (middle, ring, pinky) are controlled by a different muscle group which includes the abductor digiti quinti, flexor digiti quinti brevis, and the lumbricals of their respective fingers (I'll call this group the hypothenar muscles). Note that the middle finger only is controlled by a lumbrical and not of any of the hypothenar or thenar muscles. Therefore, it doesn't matter whether or not you use the middle finger with the sword. The same is technically true for the ring finger, but many people have difficulty independently controlling the ring from the pinky, and so the two tend to move together. You could, theoretically, control a sword with only a pinky grip, but I suspect only a good pianist or guitarist could do this, as they have trained to be able to independently control their ring from the pinky sufficiently. Nevertheless, you do want some control over the thing you're holding. Read on:
Now, when you are gripping a sword, you want your hand to be as flexible as possible. That cannot happen when the thenar muscles are tensed and in contraction. You want as much free wrist flexion as you can get, while still holding onto (and controlling) the sword. When the thenar muscles are tensed, they are said to be "in contraction" (that's how all muscles do work: they contract). And in contraction, you may note your wrist loses some flexion. You don't want that when you need your wrist to flex with an object where precision control is needed.
The reason for this is that when both muscle groups are activated, both are contracting, and are controlling the object being held. In order for you to precisely control the sword, you need to dexterously contract and relax the thenar muscles, and time it properly with the desired action you want. This is extremely difficult to do, and what's more, this contributes to fatigue. Ever use a sword for a long period of time and your hand gets tired? Try not to squeeze with the thenar muscles next time, and see if you are thus fatigued in the same way.
When you want rigidity and absolute control, then you need to engage the thenar muscles. This tenses and strengthens the whole hand, and flexion is more limited.
So, fencers, swordsmen, golfers, baseball players, writers (pen/pencil) all need more flexion in the wrist, and are taught many methods to not tense the thenar muscles. In fact, some people have difficulty independently controlling these muscles. Children, for example, often have difficulty, and it is evidenced in their handwriting. Once they learn how to independently control these muscle groups, their handwriting and stamina improves.
And when strong grip is needed, such as when grappling, lifting weights, shooting a gun, using some tools, skiing, hiking (with a pole), or using a knife (eg, for kitchen, butchery, or self-defense), then you tend to want the whole hand as rigid as you can get. Stability is important here.
Here is some more information on the Thenar eminence, which describes how the thenar muscles work and are enervated. It might suprise you to know that not everyone has the same nerve control over these muscles.
You may also find information in the Hypothenar eminence, which describes the other side of the hand.