What could be the cause of upper leg pain when lying down?

Tight proximal quad. Hip flexor tightness common today from all the sitting and stair steppers and no quad stretching we do our hamstrings and calves few stretch the hip flexors or abductors remember middle school pe and the hurdler stretch second part lying back.
Many things. It may be coming from your back, hip, or knee. I would suggest evaluation by your physician.