Dogs show an incredible ability to understand their human companions, even without extensive training. The question is – how much of this ability is innate vs trained and how much is shared with wolves?
Humans are a potential source of food, and perhaps even protection from even larger predators.
Therefore, it’s possible that protodogs were already highly evolved for human compatibility before humans went from tolerating them on the fringe of their living space to welcoming them into their living space.
Once that transition happened, then the evolution of dogs would have progressed rapidly. It’s also possible that this was a two-way evolution, each species adapting to some extent to the other. The result was a symbiotic relationship. Dogs now had a far more reliable source of food and protection. In return they provided companionship and protection to their human symbionts.