Actually, some do come with chainguards, just not all models. You'll find full-coverage pants protectors on some cruisers and smaller chainguards intended to keep trousers out of the front sprockets on some urban bikes. They're on these models because the designers recognize that you're likely to ride in everyday clothing, which is loose fitting and can get caught in the drivetrain. And they expect that you're not overly concerned with a little additional weight.
These same bike designers assume, however, that you'll pedal your mountain and road bikes in cycling garb that's unlikely to catch in the drivetrain, which is one good reason chainguards are rare on these machines. But, there are other explanations. The primary one is that if you ride rigorously as is often the case off road, and on (if you push the pace), guards can get bent and interfere with the shifting system by blocking the action of the front derailleur, which relies on precise lateral movements to move the chain. Guards can also loosen and rattle, and they add weight, all things that can drive you crazy on any ride that lasts more than a few blocks.