Insomnia and The Machinist both works with the theme of guilt being the cause of insomnia. But is it based on any real facts? Is there any recorded case of guilt being the cause of insomnia? Or is it just made for fictional purpose?
Yes it does. Depression is is strongly correlated with guilt and insomnia since both are indications for depression. There are actually many psychological studies which proves this, but you may read about in Huffington Post:
Insomnia is often related to depression or anxiety. People with depression may have early morning awakenings and spend more time lying in bed than is needed, thus causing a worsening of insomnia. Symptoms of depression include sadness, feelings of guilt, poor attention and concentration, decreased libido, increased crying, lack of desire to do things that are enjoyable and lack of pleasure when doing things that you used to enjoy. - Article
Now, you don't have to actually have depression to have some of its symptoms, like insomnia...
That's not to say insomnia or other sleep problems are caused only by depression. Insomnia is the most common sleep disorder in the U.S., affecting nearly one out of every three adults at some point in life. More women suffer from insomnia than men, and as people get older, insomnia becomes more prevalent. - Article
... but most of the causes of depression, cause insomnia.
Are there more emotional insomnia causes? Absolutely. The six I have mentioned are really just the beginning. Don’t forget, there’s also guilt, regret, remorse, grief, confusion, shame, embarrassment, unrequited love, lust, longing, discontentment, and possibly one of the most important ones in the insomnia world–frustration! And especially, the frustration at not getting the sleep we so desperately want! - Article
I found an actual Psychological Study by Max Hamilton which scales depression's symptoms and progression. As we may see in his table CORRELATION MATRIX OF THE SCALE FOR DEPRESSION, he specifies that Guilt is just two steps ahead of Insomnia in the Depression progress.
Image taken from: A Rating Scale For Depression by Max Hamilton