For some, it is characteristic of their breed. They are going after prey, real or imagined. Dogs that are confined to a yard have a great need to dig. During the winter, they dig to build a den or warming chamber. During the summer, they dig to create a cooling pit.
Some dogs dig to escape.
They want to escape because they are domesticated and, therefore, have a great need to be with people. Dogs also need to be with their own kind from time to time and, if confined, will dig to join their canine companions. Most dogs dig to bury bones and, later, to recover them. Whatever the reason, your solution to this problem will be to eliminate your dog's motivation for digging or to redirect the digging from an inappropriate to an appropriate place. Punishment for digging will create more stress and result in an increased rate of digging as a means of alleviating tension.