Grima's betrayal is very similar to Maeglin's (of the First Age). Both of them lusted women they knew they could not get.
In the case of Maeglin, he desired his cousin Idril. Unfortunately for him, "the Eldar wedded not with kin so near". Knowing this, he became angry and jealous, these feelings grew upon the arrival of Tuor, who then wedded Idril. Finally, when Morgoth captured him, Maeglin turned to evil and betrayed Gondolin.
Thus all seemed well with the fortunes of Maeglin, who
had risen to be mighty among the princes of the Noldor,
and greatest save one in the most renowned of their
realms. Yet he did not reveal his heart: and though not all
things went as he would he endured it in silence, hiding his mind so that few could read it, unless it were Idril
Celebrindal. For from his first days in Gondolin he had
borne a grief, ever worsening, that robbed him of all joy: he
loved the beauty of Idril and desired her, without hope. The Eldar wedded not with kin so near, nor ever before had any
desired to do so. And however that might be, Idril loved
Maeglin not at all; and knowing his thought of her she loved
him the less. For it seemed to her a thing strange and
crooked in him, as indeed the Eldar ever since have
deemed it: an evil fruit of the Kinslaying, whereby the
shadow of the curse of Mandos fell upon the last hope of
the Noldor. But as the years passed still Maeglin watched
Idril, and waited, and his love turned to darkness in his
heart. And he sought the more to have his will in other matters, shirking no toil or burden, if he might thereby have
power.
Thus it was in Gondolin; and amid all the bliss of that
realm, while its glory lasted, a dark seed of evil was sown
Now what about Grima? Well, we have no idea when Grima started lusting for Eowyn, but it was presumably when he first saw her (in womanhood). Knowing he would never get her, he resorted to "haunting her steps" and "watching her under his eyelids" -- basically stalking her. Finally, Saruman, needing a spy in Rohan, convinced Grima to betray Rohan.
In both cases the delusion of getting the woman they desired by betraying their kindred was implanted into them, by Morgoth and Saruman. It was because of this that they turned to evil.