Dogs, when nearing the end of their lives, often seek out places they perceive as safe and hidden, away from their owners. They do this not out of malice, but as a natural instinct to find peace and solitude as they approach death. Besides this, some dogs will quietly wait to pass, sometimes even actively leaving home.

It's a common belief that dogs have a sense of when their time is near. Typically, after a farewell to their owners (although not always apparent to us), they might choose to leave home and hide, or find a secluded spot within the house. In these instances, they often just want to find peace in death without being disturbed.
Many people report that dogs will dig their own graves before passing away. In the wild, where animals are often hunted, digging a hole to bury themselves serves as a survival mechanism to avoid being preyed upon. Some domestic dogs retain this innate behavior.
Historically, dogs' ancestors lived in packs that followed a "survival of the fittest" hierarchy. If a dog was injured or sick, the stronger members might choose to eliminate them to avoid any negative impact on the group. In this context, sick or injured dogs would move away from the pack to prevent being a burden, or to let their bodies decompose and prevent the spread of disease. This innate behavior of avoiding contact when ill is still seen today in domestic dogs, and they might instinctively seek secluded, dark areas to heal or pass away.