Why do I get hand or finger pain from playing the ocarina?
There are quite a few factors which may cause hand or finger pain while playing the ocarina:
Being new to the instrument
It is normal to experience some amount of discomfort while playing a new instrument, as you are asking your body to to something it is not accustomed to.
Playing the ocarina requires holding your hands up for an extended period of time, using muscles you are not used to using, and putting your hands into an unnatural position.
This will go away after a few weeks.
Holding the ocarina too tightly (aka the 'death grip')
You may be holding the ocarina far too tightly, and a way of telling is If the area around your fingernails turns white. If that happens, relax your grip.
New players commonly hold the ocarina extremely tightly in fear of dropping it, but there is no need. Any well designed ocarina is made to balance in your hands, and can be held loosely.
Looking down while playing
Ocarinas are normally balanced to rest on the right thumb when held parallel to the ground.
If you look down, most of the instrument's weight is instead put on your left pinky. The pinky is a much weaker finger, and doing this can be painful.
Just look straight and preferably stand while playing the ocarina. If you are looking down to see sheet music, get an eye level music stand.
Slouching
Due to a number of factors including chair design, poor ergonomics in computers, and a lack of awareness, a slouched posture is common in Western cultures. If your chin is below your shoulders when you look at yourself in a mirror, you are slouching.
Slouching can cause hand pain while playing the ocarina as your body is interconnected. Slouching can force your hands awkward compensations, which can be painful in some cases.
Try to stand or sit upright, with your elbows relatively tight to your body, your wrists straight, and a gentle curve along your fingers. See How to hold an ocarina for more advice on posture.
Forcing your right thumb backwards, or covering the right thumb hole with the tip of your thumb
If you are able to bend your thumbs backwards, take care that you don't do so in 'resting' position while holding an ocarina.
Forcefully bending your thumb back puts a lot of strain on it and may also cause pain in the thumb. Bending your thumb back like this also makes it impossible to play the high notes effectively.
Covering any hole, including the right thumb hole, with the fingertip is also not recommended. Doing either of these things tends to force the other fingers to make sharp bends and this can be painful.
The alignment of the thumb and finger holes
An ocarina may cause you hand pain if the alignment of the thumb and finger holes are poorly suited to your hands. If they are not, it may force the wrists to fold back hard, which can cause wrist pain.
Ergonomics is not a one size fits all problem, though, as the relative lengths of different peoples fingers vary. For me, positioning the finger holes directly opposite the thumb hole allows my wrist to be neutral, but it will probably be different for you.

You can compensate for an ocarina that is not ideal for your hands by allowing your fingers to overhang the holes. The only catch is that you need to be careful not to cover subholes if applicable.
Your hand posture
All of these factors are made more complicated by the fact that there is a great deal of flexibility in the hand, and consequently many different ways to hold an ocarina. If any of your fingers rest at odd angles or have sharply bent joints as in the following picture, try to adjust your hand to reduce this.
As everyone's hands are different, you will need to experiment to find a position that works for you. You can try experimenting with the following things:

The rotation of your forearm
Rotating your forearm changes how the fingers relate to the instrument, causing different parts of the pads of the fingers to cover the holes. At extremes, it forces fingers to lie at odd angles relative to each other.
The fold of your wrist
How much you fold your wrist changes which part of the finger pad covers the holes. Pivoting the wrist down too much can make it impossible to cover the top holes with the pads of the fingers.
The pivot of your wrist
Wrist pivot has a similar effect to forearm rotation. Pivoting to the left causes the left fingers to curl more. Pivoting to the right does the opposite. Aim to find a position that allows all fingers to have a similar curl. Note that the pinky is normally straight as it is so much shorter than the other fingers.
The curl of your palm
Your palm isn't an immobile slab. It can curl across its width, varying between flat along the tops of the knuckles to visually curled. This movement is quite subtle, and has proved difficult to show clearly in photographs.
How you curl your palm changes the positioning of the tips of your fingers relative to each other. It is also useful for playing ocarinas with split holes, as the palm can be curled and uncurled to cover and uncover the hole. I find this easier than curling the finger.
How the fingers are curled
You can vary how your fingers are bent along their length, from keeping them relatively straight and bending from the knuckle, to having them curved gently along their length as shown above, to having almost all of the bend in the last joint of the finger.
Generally, you want to take a middle ground here and have gently curved fingers. That being said, going to one extreme or the other may be needed depending on the relative lengths of your fingers, and the ocarina.