People often pat the top of their dog's head because it is an easy place for them to reach. Your dog may be used to you doing it but watch his body language. Does he really enjoy it?
There are dogs that don't mind this if they are comfortable with the person doing it, but there are dogs, such as the typical shelter dog that just doesn't like it. They may have been abused or have had a bad experience that you just aren't aware of. Therefore, if you do not know a dog very well, it's best not to touch his face. The safest is to touch a dog on his chest or back to not bother him. Leaning over a dog to touch him is not appropriate either because it might make the dog think you want to attack him. When a dog is not sure about a human's intentions he usually moves his head away from the person's hands.