I find the most common reason I sometimes can’t fall asleep is that mental stimulation you talked about. It’s hard for me to concentrate on writing until my husband is asleep because he frequently interrupts my work. I have a heart medication I have to take exactly at 10 am and pm. I normally write from 10 pm until 2 am. Then I sleep until my timer rings at 9:45 am. I wear a sleep mask to keep electronic light out of my eyes and I have a playlist I designed to make me sleepy and block noises from outside that might keep me awake. These methods usually let me fall asleep in a few minutes.
If I get on a writing binge and can’t stop or I started a mystery I can’t put down, I may stay up later than I intended. Then when I do try to sleep after 3:30 am, I find I can’t. The next morning after I wake up with the timer and I’ve taken my pill, I’m too tired to work. I often turn over and go back to sleep until noon . I need to avoid mental stimulation after my normal bedtime if I want to sleep well and be ready to function when the timer goes off.