The solution is simple: Don’t.
I was born a nightowl. I get my best energy at 3am, which means my circadian rhythms are diametrically opposite those of the daylark majority. Even as a child, I’d hide under the blankets until the sun came up, reading with a flashlight, because I just wasn’t tired at night. There is evidence that being nocturnal is genetic and can be inherited, which makes sense from an evolutionary perspective; there is a survival advantage to the tribe if a small minority remain awake, energetic, and on guard while the rest of the tribe sleeps. If you just aren’t tired at night, then don’t sleep at night.
On the other hand, if you’re genuinely tired and just can’t fall asleep, as someone who occasionally experiences insomnia, I have an excellent solution which works 100% of the time: stay awake. If you simply stay awake long enough, the insomnia will be cured, every single time.
However… it seems from reading between the lines of your question that this isn’t really about sleep at all, but about the dread of being forced to lie motionless with your thoughts clear and lucid. I have experienced severe, crippling, and untreatable clinical depression all my life, and I know well how it feels to be alone and terrified and utterly without hope. The problem is that those feelings are right and you know it. The world is a harsh, dark, dismal, unpleasant, brutal, lonely, horrible place.
Repeated clinical studies have shown that people who are depressed show marked superior judgement to those who are not depressed. For example, depressed people are much better at judging whether a given shape will fit a given hole than those who are not depressed, who err constantly on the side of optimism. This suggests that depression is really just the removal of a filter which makes the world appear irrationally pleasant and fair to everyone else.
To be forced to see things as they really are in a world of fools and mealy-mouthed pollyannas with rainbows and unicorns shooting from their quivering assblossoms is a terrible thing. The reward for enduring this is suffering and pain. While this might not seem like much of a reward, bear in mind that existential choice is always, by definition, painful. Those of us who see the world as it is, and who stand unflinching, gazing into the Abyss, have made an existential choice to do so. No animal can do it. The vast majority of the population will not. In the case of animals they are driven by the flesh to avoid pain, and in the case of people they lack the Will to bear it. Only the great haters, the “arrows of longing for the other shore,” as Nietzsche put it, have the strength to bear the burden of lucid perception. Don’t be afraid to lie in bed and feel the weight of loneliness and despair in your heart; accept it. Let the pain burn away what is common in you and reveal the Overman who fearlessly strides where angels fear to tread. You won’t be happy, but you will be great.