I think you’re asking why girls touch and play with their hair when they’re around a guy they like, right?
I think the main reason is long hair is typically historically (maybe biologically?) seen as a sign of femininity, beauty, and sex appeal, so they’re subconsciously playing it up.
Also, it’s something to do with their hands when they’re nervous!