Let's take a look at Ionian mode. Its pattern is "WWHWWWH". Which there are 7 steps. If we consider this mode building problem as a permutation problem then we can arrenge them into 7!/(2!*5!)=21 possible modes. (Since this is a permutation with repetition and there are 5 W's and 2 H's.) I wonder why are we talking about just 7 modes instead of 21 possible modes? Are they historically important or do I make a mistake here? (mathematically or in music theory context?)
By very definition, the modes are created by taking the Ionian scale/mode and starting at a different point, not by rearranging those intervals at will. According to wikipedia:
Modern Western modes use the same set of notes as the major scale, in the same order, but starting from one of its seven degrees in turn as a tonic, and so present a different sequence of whole and half steps.
The diatonic intervals have been created by jumping around the circle of fifths (funnily enough the C ionan is created by starting in F). Try that: start with F, jump 5ths, and you'll get all the notes that make up the C ionian. Why circle of fifths? The 5th is the next "most fundamental" interval after the octave (octave is double frequency, 5th is 1.5 times), and it was used back in ancient times to build scales and modes.
Your suggested formula (the permutation of intervals), would yield a combination like HHWWWWW. I don't think there is any circle of fifths combination that would yield that scale.
Note, of course, that you're free to create musing using whichever scale you want. Nobody is telling you that you must stick to any of the modes. Furthermore, many pieces go out of diatonicity often.
Other answers have pointed out that generally 'the modes' refer to the different points at which you can start on the diatonic scale.
As to why that particular repeating sequence ("WWHWWWH...") is important, it's because that sequence of intervals creates frequencies that have particular ratios between them that sound harmonious. Not all permutations of whole and half steps would have that useful property - that's why treating it as a permutation problem doesn't work if you want to make 'nice-sounding' music.
There are infinitely many modes... because there are infinitely many scales to base them on. Most of these scales don't have any notion of whole and half steps at all.
But when we're talking about “the modes”, what's generally meant is specifically modes of the diatonic scale, and that constrains you that the half-steps must be seperated by either two or three whole-steps.
There are more modes. There's nothing that says that a seven-note scale needs to have two half steps and five whole steps. Many scales have an augmented second, which is (in 12-tone equal temperament, precisely) three times the size of the half step. For example, you have the harmonic minor scale, which looks like this if you use X for the augmented second:
W H W W H X H
You can also have a scale with two augmented seconds:
W H X H H X H
These scales are in actual use. European music (speaking broadly to include music derived from European harmonic theory, including issuing jazz and popular music) doesn't necessarily keep strictly to a seven-note scale. A piece in C major might actually use all twelve tones. This is how the harmonic minor scale can be associated with the Aeolian mode even though it doesn't contain the same intervals.
In fact, the historical modal system that immediately preceded the development of major and minor tonality effectively had only four modes, which developed into the major and minor modes of the common-practice period because of chromatic alteration. Around the same time, someone came up with the idea of the Aeolian and Ionian modes, and rather later someone came up with the idea of the Locrian mode, which isn't really used except as a curiosity.
The Locrian mode was invented to fill out the generalized abstraction of mode as the result of picking any white key on a piano keyboard and playing an octave scale using that key as the starting and ending note and playing all the white keys in between. It is of course that definition of mode that leads one to a total of seven possibilities, and that answers your question "why do we have to put them into circle?"
If you take the broader definition of all possible seven pitch scales in a 12-tone system, the number of modes is equal to the number of ways you can pick an ordered sequence of seven integers between 1 and 6 having a sum of 12.
There are also scales that have fewer than seven tones in an octave, or more. There can also be scales that have pitches closer together than a half step; such scales cannot be approximated with 12-tone equal temperament.
Why are there just 7 modes?
Because your concept of the permutation-possibilities of the 7 modal scales and steps is wrong. The modes are derived from 2 identical tetrachords: 1*)
C D EF - G A BC (WWH - W - WWH)
Now the modes are the 7 possible scales that begin on the different degrees of the scale of C major: C D EF and G A BC:
1. C -> C, 2. D -> D, 3. E -> E, 4. F -> F, 5. G -> G, 6. A -> A, 7. B -> B
and nothing more.
C D EF G A BC => Do Re MiFa So La TiDo
re mifa so and la tido re (WHW) or do re mifa and so la tido. (WWH)
(mind that between the 2 tetrachords there is another whole step!)
I am assuming that you are referring to the 7 modern modes. They use the structure of the intervals of the major scale--the "WWHWWWH" you mentioned--and keep this structure (note, though, that you could also choose the minor scale or another scale structure). As the others pointed out, you then "make a circle" with it and choose a different starting point.
Your permutation calculations, on the other hand, consider all the possible positionings of the half-steps (e.g., "HHWWWWW").
Keeping the structure of the major scale, for instance, allows you to construct a scale that is "compatible" with a chord constructed on this scale. For instance, if you are playing the V chord, the Mixolydian scale will contain the notes of the V chord. Check out also this Wikipedia link on this subject.
The other scales you can make like this are also valid, but also a bit weird sounding and not in especially widespread use in a pop or classical context. But check out ascending melodic minor for a partial counterexample. It goes WHWWWWH.
In general you can classify these scales by how far away the H's are. There's 7 scales in which the H's are adjecent, 7 in which they're 1 apart, and 7 in which they're 2 apart. Each of these has a unique mode that's inversion-stable, and you can get the other modes by cycling the notes around. For example, Dorian is the unique 2-apart inversion-stable scale, and you can get the other 2-apart scales by cycling this around.
A lot of these answers indicate that your method violates the definition of diatonic scales, and how when we talk about "the 7 modes" we really mean diatonic modes. There are plenty of non-diatonic modes.
Other answers mention why there are only 7 diatonic modes, but here's another way of looking at it. Take a C-Ionian scale [C D E F G A B], add a sharp, and you have a C-Lydian scale [C D E F♯ G A B]. If we want to discover another mode, we add another sharp, right? So we get [C♯ D E F♯ G A B]. But now the root has changed, so we can't call it a mode on a C scale anymore.
The same applies in the other direction. C-Locrian is [C D♭ E♭ F G♭ A♭ B♭]. To get another mode, we would add another flat, but we end up with the same problem: [C♭ D♭ E♭ F G♭ A♭ B♭] no longer has C as the root.
There isn’t just 7 modes at all, 7 only in diatonic scale.
Modes aren’t in arrange or permutation math, they’re more complex than this, even more complex than cyclic permutations. They’re more prone to algebraic objects like rings, bracelets and necklaces. In short: too complex to calculate, it’s easier to use set theory to account all modes in a given collection. Or use Ian Ring’s scale finder site.