It's a matter of dosage. Lower doses are more likely to act as anxiolytics, while higher doses will act as hypnotics. Diazepam is a fairly weak benzo though, and rarely used as a hypnotic. In a hospital setting, diazepam is usually used to prevent alcohol withdrawals, while temazepam or zolpidem is used for sleep.
Either way, the evidence shows that benzos (whether traditional or z drugs) A. give poorer quality sleep, B. produce dependence for sleep initiation, C. cause an addiction with significant crossover to alcoholism, involving the risk of delirium tremens and death on withdrawal and D. have no place in the clinical treatment of insomnia outside of short courses or specific targeted uses (such as before sporting events for elite athletes).
Best practice treatment of insomnia is nearly always behavioural modification, except in very specific circumstances.
That doesn't mean there aren't GPs who don't prescribe these drugs long term and willy-nilly, but they're the same group of GPs who throw anti-biotics at every patient who comes through the door so that they can get the patients through as quickly as possible.