The Root of the Behavior
To decipher the cause of the behavior it is important to look at when it began. Did this begin when they were a puppy or after they became fully grown? Does it seem like they do it compulsively to relieve stress or excess energy? Dogs can have behaviors such as these develop seemingly from nowhere in the first couple years. Often, in this case, it has no underlying medical condition, however, should still be addressed as head pressing itself is not a healthy habit and can, over time, cause other medical concerns. Dogs who begin doing this in their later years may have begun in reaction to something. The seemingly out-of-the-blue type of behavior is what you really need to watch out for. They could be pressing against the wall as a reaction to fleas or to a lump forming on their head. In this type of situation, you should reach out to your dog's veterinarian for a full work up. You should not be alarmed, however, you do want to know if it is being caused by something serious.
Encouraging the Behavior
Some types of toxic poisoning can cause neurological damage and cause the head pressing. Ensure cleaning chemicals and other toxic solutions remain out of reach and be sure to rinse the dog bowl well after cleaning. Ensure they are clean and there are not any wounds on the scalp. Any kind of itching could be causing the behaviors, much like a human would use corner to scratch their back. Contacting a behavioral specialist should be considered if you cannot get the behaviors to stop yourself.