Dogs are creatures of habit and love marking their territory. They leave scratches on their beds for the same reason they pee on a fire hydrant when you take them for a walk.
Before they became domesticated by humans, survival in the wild was rough for dogs, and they needed every instinct they could to stay alive.
Dogs scratch their beds to soothe themselves when feeling anxious or fearful because it helps them settle down.
Dogs are like us when it comes to being living beings that love forming habits. Most of them pick this habit up as puppies because they observed their mother or another animal in their home doing it.