Having the occasional headache when diving in not really much of a deal, so it is really only those who regularly experience such discomfort that need to address the possible causes. The reasons why you might have a headache are too numerous to list but, assuming you are a normal healthy person who doesn't suffer frequent headaches in normal life, what can it be that is causing you this pain?
Is your mask too tight? Remember the mask strap isn't meant to be pulled tight as if it will come off otherwise. A well-fitted mask can stay on underwater with a good seal even when the strap is hanging loose, so make sure that you haven't tightened your mask too much. Also as the depth increases so too do the air spaces decrease including the air space inside your mask. This causes mask squeeze easily solved by allowing a little air to escape from your nose into the mask. Failure to do this can obviously cause you a headache as well as an unsightly mask mark on the face which won't impress that incredibly good looking person on the dive boat.
How far down the tank is your BCD strap? Everyone has their own preferences but if others assemble your gear it may not be just the way you like it. Sometimes a tank is so high on the back that the diver needs to keep their neck bent forward to avoid collisions between the top of the tank and the back of the head. This constant tension can soon lead to pain. So make sure your kit set up doesn't restrict your movement.
We have all seen divers, especially on liveaboards puff through a couple of smokes and gulp down a large caffeine-heavy cuppa in the morning before taking the plunge. It doesn't take a genius to work out that such stimulants have an effect on the body and its organs that can cause headaches. After all, we are designed to drink pure liquids and to breathe air, so it may be worth looking at your pre-dive routine before blaming diving for your sore head. Incidentally a big night of boozing the evening before is clearly a more likely cause of a dehydration headache the following day than anything to do with the activity of diving.
One of the greatest things about diving is the fact that you get to take in the myriad wonderful sights of the undersea world. No-one wants to be 'The One' who didn't see the highlight of the dive, whatever that might be. However your body position in the water and how you move around in order to take in the sights might be the cause of your cranial discomfort. Finning along with a horizontal body position and making your neck do all the work looking left, right, up, down and behind you can cause stress. Better to relax your neck and change your body position to allow you to take in the sights without the pain caused by hyperextension of the neck.
Breathing and headaches are clearly closely linked. Breathing bad air can give you a headache. When you have a headache you often crave 'a bit of fresh air'. Are you breathing in a relaxed manner? Shallow rapid breathing is a shortcut to a headache. So too is skip-breathing. The best way to improve your air consumption is to stop thinking about it. Relaxed, slow breathing of air from a scuba tank should be no more likely to give you a headache than normal breathing at the surface.
Are you biting down on your regulator mouthpiece? This is a very common action for divers before they become regular, experienced divers. If it wasn't, why would so many rental regulators have their mouthpieces practically hanging off? A tense, clenched jaw and a headache go together like American foreign policy and Global Terrorism so what to do? Well (in either case) stop and think about what you are doing and how you are creating the problem. Then stop biting down on that mouthpiece. Also available on the market are mouthpieces which you warm in water then bite into them moulding them to your upper teeth. The result is a mouthpiece which fits like a glove and helps you forget it is there. No more clenching or chewing - no more headaches.
If you are sure that none of the above apply to you then maybe you need to look within for the cause. Relax, stay fit, have regular check-ups and make sure you have the right amount of thermal protection when diving. Scuba diving can and should be a fun way to spend time on holiday. It is such a shame to allow headaches to get in the way of your fun. However following the above steps should go some way to making your scuba experience more enjoyable and pain-free.