It's usually when they smell something that interests them
Its the flehmen response and while it is widely believed to be their way to sort of "smell" with an organ that senses pheromones. It's been seen in stallions detecting whether a mare is in heat or not. Geldings and mares also do this as a behavioural movement. We don't know what the flehmen response as a behaviour might indicate but its interesting to observe it.
Great question, and I have a follow up, if I may?
My mare does this every time I go to put the bridle on her. And I mean every. Single. Time. She does it with either bridle (I have 2), they both fit her perfectly and once she's done this lip lifting with head in the air she calmly accepts the bridle and we carry on! She is totally chilled in every way, this is not distress but I'd love any insight into what it could be. It's actually very funny!
It's called the Flehmen Response and it's what Jack Robbin said.
The horse that perceived an unusual or very laden smell turns the upper lip, giving it the air of smiling, stretching its neck and head up. He then noisily inspires. The animal thus acts when it wants to memorize or analyze an odor, like the mother at the birth of her foal, or the male when crossing the dung of another stallion or the smell of a female in heat.
Often it is the males who adopt this attitude, but it is enough to present to an equine an object having an odor that it does not know so that it tries to identify it in this way. It may be, for example, a pool in which it drinks for the first time, or an unknown food (however, in horses, this posture, when repeatedly adopted, is characteristic of horses suffering from colic).
Have a good day :)