Good question. And K9s are supposed to be well trained, how does one wander off?
My late male German shepherd developed a fear of thunder and fireworks around the age of 2. As a pup, it didn’t seem to bother him. His behavior during those times were not under his control - it was as if a demon was released inside him. No aggression, just plain fear. He would run from door to window trying to escape what was going on inside of him! I learned to cope by crating him and giving him Rescue Remedy (GNC) as soon as he started. His only safe places were in his crate or on my lap! Training had nothing to do with it. The dog cited above broke through a window and through wooden fence boards. That was fear - not “wnadering off”.