In Shohei's flashback, we can clearly see that Tamaki had short hair as a kid, so my theory is that sometime between then and now she made a Faustian bargain with some demonic entity to get her exceptionally long hair. This was presumably to attract Shohei's attention (maybe after he commented off-hand that he likes long hair or something) which she succeeded in doing while also isolating him from other girls.
Now I think the hair IS the Oni she made the deal with and has been possessing her so it can regain its form (I think!). Dying on the train tracks was the final step for them both to attain full demonhood I believe. And the demon also convinced her that turning herself into an Oni and devouring Shohei and turning him into an Oni too was the only way to stay with him forever...
Or something like that! I like how the author gave so much space for speculation personally! Really gets my noggin joggin' as they say, and keeps the exposition to a minimum.