If you feel sharp pain in the lower back, then you need to adjust the exercise.
The reason why lying leg raises are often painful, is that the lower back gets pinched and compressed as the weight of the legs tilts the hip and pulls the lower back upwards. The main leg lifting muscle is the psoas major, which connects your thigh bone directly to your spine. Resisting the anterior pelvic tilt in the lying leg raise is very difficult, as the forces on the hip and spine are very strong because of the leverage of the legs.
The only way to fight those forces is bracing the abdominal muscles, those, that in a neutral position would bend the spine forward (in the opposite direction). However, most people do not have the abdominal strength to counterbalance the weight of the legs when they are lowered, a very disadvantaged position because of the leverage of the legs on the psoas (and thus, the spine).
This is the reason why putting your hand under the back works, because it supports the back and decreases leverage. However, this is not the way I recommend approaching this exercise. It is better to gradually approach it by doing "one-leg raises" (with the other leg bent and supporting), making sure your abdominals are braced and the lower back is flat on the floor throughout. When you can do as many of these as you want with control, tension in the abdomen, and pain free, then progress to two leg raises, but lower them only to 60 degrees (lower back always flat on the floor), then 45 degrees, and so on. Only progress if you are completely pain free and easily in control of your legs and spine.
Hope it helps.