Almost anything can cause it.
Cognitive-behavioral psychological techniques is how you desensitize them to that fear. Although depending on how young they are, they may NOT have enough cognitive sophistication TO use CB therapy ... in which case you just give them the security they need ..and wait for them to outgrow it.
You can even bring in the "family bed", where the child sleeps in your bed every night ... eventually, once they feel secure and outgrow their fear, they will seek out their OWN bedroom for sleeping and you can reclaim your bed for just you and your spouse.
I have known families that took their infants into their bed (mattress on the floor, so there is no danger of falling out) and kept the child there until it was ready to seek its own bedroom .. usually around age 6 or 7.
These children have grown up to be remarkably well-adjusted people with honor and compassion and trust ... as well as being successful in life and in relationships.
So the "family bed" concept - while inconvenient at first - becomes an excellent way to raise your child.
No one is so naive to think that a toddler has enough emotional self-sufficiency to face the dark night all by themselves without the comfort of their parents.
With my own daughter, she was always welcome to join us, and didn't have to fabricate some monster under the bed, to climb in with us. She didn't do it every night, and she lost interest by the time she was 5. But as an infant, I breastfed, and kept her beside me through the night. Moving her into her own room only once she was 2 years old.
She's never given us any trouble and is now in her 30's and owns her own condo with no mortgage left on it.