Called bunting, cats rub their heads against prominent objects to leave chemical 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' Pheromone Glands
Cats have several different pheromone producing 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. 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.
When cats bunt each other, this is often done as a form of social bonding. It is done among cats who are friendly and familiar and is usually initiated by the more dominant cat as a way to make all the cats in the colony "smell" the same.
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. She is saying that you are a part of her tribe.