Called bunting, cats rub their heads against prominent objects to leave scent markings as a part of scent communication. Depending on the object of the cat's communication, they may be claiming ownership or indicating pleasure.
Cats' Scent Glands
Cats have several different scent glands all over the body. They are located between the toes, beneath the chin, the corners of the mouth, the temples, along the length of the tail, and the ears. We don't know if each gland has a different scent or not, but cats tend to use the entire head in sometimes luxurious rubbing displays.
Which part of the head is used depends on the height of the target object. The forehead and ears usually are rubbed on the highest objects while head-height objects are marked with a swipe from the corner of the mouth to the ear. Lower objects get rubbed with the chin and throat.
Although rubbing between cats seems to take place most often between cats of different sizes, experts aren't clear on the specific understanding of this interaction. It's speculated that bunting, when directed at another cat, serves to redirect aggression—perhaps the cat equivalent to showing the peace sign.
Head Rubbing on Owners
Some cats become pushy and turn the behavior into a head-cracking contest (ouch!), while others slowly rub their body and tail around and around human ankles.
We can't know for sure, but cats tend to scent-mark objects that are most important to them. They use rubbing with friendly cats, not with strangers. A cat who head-rubs your face with wide open eyes close to your face pays you a huge compliment in terms of trust by placing herself in a vulnerable position.