Why do wizards have magic, but Muggles don't? Why don't all people have magic, or no people have magic?
First, I think you are mistaken in your question - it is not only wizards who have magic, but also witches. And magical creatures, but surely they don't count... (shifty eyes)
The answer to why it can't be everyone with magic, or no one with it, is that people aren't all the same. There are people with a variety of talents and strengths, and a variety of weaknesses - like being colorblind or tone deaf, or like having double-joints or webbed fingers, being pitch-perfect or having a photographic memory. Some people have a talent, some don't. Those that do might want to breed widely so it will not be lost, others to restrict it so they can keep power in fewer hands.
As to the actual source of the magic bloodline, I believe it is not mentioned in canon. There are a number of possible theories, but they're speculation.
I seem to recall Rowling mentioning that magic, in her universe, is genetic - that muggle-borns inherit their magic from a witch or wizard somewhere in their family tree. One theory, then, would be that it started with some genetic variation, perhaps one common enough to keep producing muggle-borns, or maybe one rare enough to have every magic user eventually originating with a single individual.
Another option would be, given that there is evidence that interbreeding is possible with at least some magical species, notably giants (Hagrid) and veela (Fleur), it is possible that the original magic in the bloodlines might have come from such creature interbreeding. This might make sense of some specific magic talents, like physical toughness from giants, parsletongue from some snake-shifter, or anything else. Magic talent, generically, would come from the mixing and dilution of such heritages until they did become generic (or nearly so). So those born with magic in their mixed blood, evolved unique ways of drawing on that magic for their own purposes.
A third option might be the ability to do magic might come from being exposed to magic - being changed by magic. This might have started as staying in places heavy with magic or eating magically charged foods, and the more magic shaped them, the more they were able to channel the magic into other forms - like making 'potions' of their stew with magical ingredients. Evidence for this theory might include Umbridge's belief that working with magically charged materials might allow someone without magic, a kind of limited access (as in her accusations against muggleborns, using the wand as an example). Or it might come from the wands themselves, where a person cannot use magic without bits of magical creature and wood - it may be their native magic talent channeled through the wand, but it may have begun with somehow concentrating or harvesting the magical properties of the wand components.
There might be other possibilities, these are the first that occurred to me. But it might also be so that none of these can answer the question with certainty, because we are not told where the magic originally comes from.
Technically, I would like to reiterate my above comment:
That's the definition of wizard. If some muggles had magic, they would be wizards also, therefore only wizards can have magic
I know this isn't exactly what you're asking, but I had to say it.
I won't delve too deeply into the way-too-complicated subject of wizarding genetics, but I think that in this case it is similar to other genes. For an example, take eye color. The original humans had only one eye color, brown, and the others, such as blue eyes, are a genetic mutation.
What I'm really saying is this: magic is like other traits. Everyone around you either has dimples, for example, or does not have dimples. It's the same with magic. Everyone does or does not because of DNA.
Out-of-universe, of course, it's that JKR wanted to use the word Muggle.
Ability to do magic is a genetic trait - some have it, others don’t.
The ability to do magic is a genetic trait. People are either born wizards or born Muggles. Likely the reason why it’s not the same for everyone (meaning people aren’t all wizards or all Muggles) would be the same reason there are other genetic traits that some people have but others don’t. For example, some people can taste a chemical called PTC, while others can’t, and some people are born colorblind. The ability to do magic seems to be a similar genetic quirk that only some have.
“As intensive studies in the Department of Mysteries demonstrated as far back as 1672, wizards and witches are born, not created. While the “rogue” ability to perform magic sometimes appears in those of apparent non-magical descent (though several later studies have suggested that there will have been a witch or wizard somewhere on the family tree), Muggles cannot perform magic. The best — or worst — they could hope for are random and uncontrollable effects generated by a genuine magical wand, which, as an instrument through which magic is supposed to be channeled, sometimes holds residual power, which it may discharge at odd moments — see also the notes on wandlore for “The Tale of the Three Brothers.”
- The Tales of Beedle the Bard
Therefore, it’s most likely that the reason only some people can use magic is the same as why other genetic traits aren’t universal - put simply, some people have ‘magic genes’ and others don’t.
If no people had magic there would be no story at all. The whole point of the storyline developed by JK Rowling is this imaginary world of magic that co-exists with the non-magical world, with the non-magical folk unaware of the existence of magic.
People born with the power of magic are as natural as trees and cats and mountains in this world.