In Psalm 4:8 David writes I will lie down and sleep in peace, for you alone O Lord, make me dwell in safety. King David was able to sleep peacefully because he knew that he could trust God to help him to live in safety.
When we are not able to sleep through the night, it is often because we are not trusting God with our worries and anxieties. Perhaps we have given them to Him, but we have not let go of them ourselves?