Dogs often dig due to boredom and pent-up energy. Without enough physical and mental stimulation, they'll dig to entertain themselves.
Boredom
A dog's predatory instincts to dig for squeaking/burrowing rodents, lizards etc. can kick in when they detect movement underground.
Prey Drive
Digging in the dirt can cool down dogs on hot days. Loose soil also cushions dogs' joints as they lounge or nap.
Comfort
Dogs may dig under fences or around perimeter of yards to create escape routes in case of danger or to access something interesting.
Security
The ancestral denning behaviors of dogs make some breeds prone to digging sheltered spots to sleep or hide food.
Denning Instinct
Some dogs dig holes merely to get their owner's attention, even if the attention involves scolding!
Attention Needs
Excessive, frantic digging inside the home can indicate separation anxiety, noise phobia, PTSD, or other issues requiring treatment.
Anxiety