They are marking their territory!
Watch closer the next time this happens and you will see notice that they actually make contact with the corner of their mouth which is where one of their major scent glands are located. If you keep watching, you will also notice they will follow this up usually by rubbing their romp against the same spot. There is another major scent gland at the base of their tail that can also help define their territory.
I always get a kick out of watching my cat do this, especially when we go traveling together and she actually takes the time to mark the hotel room or the host's house.
If you move into a house that was previously occupied by a cat(s), you will notice if you look very carefully at the corners a very subtle indentation. It's so small you probably won't notice it if you aren't looking for it but it is there I promise. This is because cats don't just mark their territory once, they re-mark it multiple times. Over time, this causes a small indentation in the walls where the mark.
I've also noticed that my cat will mark a territory extra well if she encounters a new place that was previously marked by another cat.