Can mosquitos bite in self-defense?
Probably not. An immediate defense against predators requires an immediate response. The sting of Hymenoptera like the wasps and bees has an immediately painful reaction.  In addition, in the eusocial (colony-forming) species, multiple individuals typically contribute to defense of their nest. One sting may not deter a predator or invader but dozens or hundreds of stings would create an immediate deterrent.  See for example this paper by [Breed et al. (2004)] on the defense behavior of honey bees.  Animal bites that are immediately painful, such as an ant bite or dog bite create an immediate response in the organism being bitten. Spines and thorns on plants deter organisms from biting the plant. Odors released by skunks and some insect provide an immediate response.

The bite of blood-sucking mosquitoes does not provide an immediate deterrent. (Not all mosquitoes suck blood.) This paper by Ramasubramanian et al. (2008) provides a detailed explanation of how a mosquito penetrates the skin.  The paper is related to microneedle design but they are using the mosquito as a comparison for painless needle design. Go to page 3 to get a description of the mosquito anatomy and piercing behavior. Comparison of painless microneedle design to the mosquito's proboscis is instructive.  

The proboscis is the set of modified mouth parts the mosquito uses to penetrate the skin and suck the blood.  The study states that microneedles that penetrate human skin less than 1.5mm is usually painless or effectively so. These needles have a very small diameter, only about 40-100 micrometers in diameter, similar to the width of a human hair. The mosquito's proboscis is about 1.5-2.0 mm long. The diameter of the various structures used to cut through the skin and suck the blood are all less than 40 micrometers in diameter. Thus, the size of the mosquito's proboscis is so small that it does not cause immediate pain, or the pain is so little that it is an annoyance at best. In addition, the proboscis is weak enough that the moquito may have to probe the skin several times before a spot suitable for penetration can be found. 

Finally, only the females of blood-sucking mosquitoes feed on blood and have the penetrating mouth parts. Males do not. They feed entirely on nectar and water. Males would thus not be capable of such defense.