Psalm 127:2 relates to insomnia by highlighting that excessive, anxious toil that keeps you from proper rest is in vain because God, who loves his beloved, gives them sleep.
The verse suggests that insomnia can stem from trying to work in one's own strength, and it serves as a spiritual reminder to trust God, acknowledge his provision, and not rely on tireless, worried effort for the results of the labour, which are ultimately from Him.