Timing of the consequence is critical for a dog, or cat to learn an association.
Eat something, then get taken to a vet clinic to be made to vomit? Vet clinic is bad.
Eat something and feel weird hours and hours later? Why would it be the food?
Chew something and get yelled at by humans? Humans don’t like that.
Swallow an entire sock? Sick the next day? Surgery at vet clinic the next day and now finally home? What the hell? Oh, hey, look a tasty sock!
A large part of this lack of learning is that the consequences are not timed ideally for the animal to learn. Another part of it is that by selecting for domesticated traits, we’ve also selected for our domestic pets to be more more juvenile than their wild counterparts, but also to default to humans for more of their problemsolving.
You can’t really blame them for investigating the world, nor can you expect a dog or cat to think like a human when reasoning their way through the world.
I’d imagine it doesn’t help that wild canids and felids run into fewer things that are dangerous to eat. There are no chocolates and power cables in the wild.