Numerology is a real-life belief that certain numbers hold more or less magical, divine, or otherwise supernatural power. In Harry Potter it appears to be an established fact, and study of this phenomenon is called Arithmancy and is taught at Hogwarts.
The description of the discovery of the "theorem" of the power of seven from the PS3 game Wonderbook: Book of Spells suggests some sort of hard scientific process is involved.
It was one day, during breakfast, that Wenlock wrote the immensely
famous theorem that supported the magical properties of the number
seven. She wrote it down on what she thought was the back of an
envelope, in the usual invisible ink. That same day, she posted a
letter to her cousin, using what she later realised was the envelope
in which she had written the theorem.
So why, mathematically, scientifically, is seven more powerful than other numbers (and why is six so afraid of it)? Oddly enough, the precise theoretical underpinnings of the mystical forces driving the universe were left out of the children's video game.
I'm being flip, but the answer for now is... who knows? You may as well ask why thinking happy thoughts and saying Latin words make white animals shoot out of a piece of wood with a bird's feather in it. Magic in the Harry Potter is magical, defying hard explanations. Other than the fact that we know there is such a thing as "magical theory," the books go into little detail about how magic actually works (for the best, in my opinion).