It's easy to understand why your dog wants to dig a hole in your backyard. Watching them attempt the same thing on their indoor bed, however, is a lot more confusing. If you see your dog furiously scratching at a bed, couch, or carpet, it doesn't necessarily mean they're trying to escape your home. According to The Dodo, the puzzling habit is likely a survival instinct left over from their wild ancestors.
Wolves also like to dig at a spot before lying down on it, but this behavior is more practical outdoors. Temperature regulation is essential in the wild. On a cold night, digging a hole helps wolves stay warm, and when it's hot outside, digging up a bed of cool soil from beneath the surface has the opposite effect. Even if wolves feel comfortable temperature-wise, digging up a place to sleep has additional benefits. A shallow hole gives them a place to hide, so they can sleep in peace.
This action isn't as useful when a dog's bed is made of fabric instead of dirt. Nonetheless, that doesn't stop domestic pets from indulging their animal instincts when they're preparing to fall asleep. There is one other explanation for your dog's bed-digging habit that may actually lead to a better night's rest: comfort. When a dog scratches at a cushion, they may simply be trying to prepare a more comfortable spot the same way you might fluff your pillows before bed.
As long as the behavior doesn't seem obsessive, there's no need to worry about your dog's state of mind when they're digging indoors. The same can't be said for the state of their dog bed, so consider investing in one that stands up to late-night, pre-sleep attacks.
[h/t The Dodo]