The reason and what kind of doctor would treat cramps in the legs while sleeping to the point of developing an intense pain that last for hours?

Primary care. ...To start off with. Can check doppler ultrasound if exam suggests vascular issue and make referral to vascular surgeon if needed. If not, can prescribe medication for restless leg syndrome (rls) to reduce discomfort.
Neurologist. The cramps are usually caused by neuro-muscular hyper- reactivity. It may be caused by irritation of the nerve (neuropathic) or by hyper-reactivity of muscle (for instance, due to electrolyte imballance after starting water pill). If happen too ofter, an evaluation by neurologist may help. Safe and helpful initial treatment of cramps include over the counter ca and mg supplements and tonic water.