Sleeping pills may be better than getting no sleep at all, but cognitive behavioural therapy for insomnia (CBTi) may be a better treatment approach than medication [0]. A problem with sleeping pills is that they reduce sleep quality, so you aren't as well-rested versus sleeping without them. From an interview with Matthew Walker, a professor of neuroscience and psychology [1]:
"The quality of sleep that you have when you’re on these drugs is not the same as normal, naturalistic sleep. They’re classified as “sedative hypnotics,” so the drugs actually just sedate you — and sedation is not sleep."
[...] "They don’t tend to increase sleep much beyond placebos. People may be fooled into thinking that they’re getting more sleep, but actually they’re not. This was not my conclusion — it was a committee of experts, who reviewed 65 separate drug placebo studies, and their conclusion was simple: There was no objective benefit of sleeping pills beyond placebo. Their summary was that the impact of sleeping pills was small, and of questionable clinical importance.
"And my third problem: They are associated with a higher risk of death and cancer.
"About that last point, in your book you do raise the possibility that it’s not sleeping pills that’s causing those things — it’s whatever is causing you to have trouble sleeping, which weakens your immune system.
"Yeah, I think that would be the counterargument, and I think it’s a very reasonable one at this stage. But I think an equally reasonable, equally tenable explanation is that they do shorten your life and increase your risk of cancer. The answer is we just don’t know which of those two things it is.”
[0] https://aims.uw.edu/nyscc/training/sites/default/files/CBTi%...
[1] https://www.thecut.com/2017/10/the-vicious-cycle-of-insomnia...