Mosquitoes do not have a purpose. They exist to have babies and eat, just as every other animal does. They are also food for toads and bats and other small creatures. And millions of bacteria live on them too, so they’re homes (and transmitters, see malaria) for them.
Their exact form has been dictated by evolution and natural selection. Over millions of years, their ancestors gradually developed the internal and external abilities (a sharp proboscis) to consume animal blood as food, and it proved to be an excellent mutation, thus mosquitoes were able to breed and eat and breed and eat and become numerous. Their exact numbers are a function of the weather, their ability to eat and breed, and the state/number of their predators.
Trying to give them a “purpose” is pointless, as they have no purpose beyond reproducing and staying alive. What purpose does a butterfly have? What about a dog?