A climbing helmet is the first thing you should buy when you start trad climbing. They protect your head from things falling on you (rocks, equipment, etc..) and also from your head hitting the rock if you fall.
Climbing helmets are generally not worn in the gym or on overhanging sport routes. In these situations, there are no rocks to fall on your head. You are also unlikely to hit your head against anything if you fall.
In any other situation, it is worth wearing a helmet when climbing or belaying. Rocks can fall and gear can be dropped. If you knock your belayer unconscious, they won't be able to belay you!
There are two main types of helmet on the market – rigid shell and foam.
Rigid Shell Climbing Helmets
These are made of hard plastic, with an inner 'cradle' of foam or webbing so the plastic sits away from your head. They are more durable but don't tend to protect from side impact (you falling off) as well as the foam type. They also tend to be cheaper than the foam type.
Foam Shell Climbing Helmets
These closely resemble a bike helmet (don't use your bike helmet – they're designed for different impacts!). They tend to be lighter than the rigid shell, but are less durable. Be careful about throwing them in your bag then throwing it around or sitting on it!
The most important factor when buying a helmet is getting one that fits your head snugly – it shouldn't move when you tip your head. A sloppy fit reduces the helmet’s ability to protect your head.
Your helmet should adjust to accommodate a hat, and a ponytail if you have long hair. Also, make sure the headlamp attachments are compatible with your headlamp.