I've heard that explanation before, about the Great Wall of China. Even if the walls were fantastically successful at pinning and trapping escaping invaders, they failed to keep Rome secure. The barbarians kept coming past the walls, and ultimately Rome fell to them. Punishment doesn't deter invaders who are facing the worse problems of starvation or pressure at their own backs from invaders still further out. Rome needed to treat with the barbarians and understand what was driving them, then if possible address their problems, not wall them away and try to ignore them. It might not have been possible for Rome to solve the barbarians' problems, but the walls were definitely no solution. Nor was it a solution to declare that the barbarians' problems were not Rome's problems. Problems do not ask for permission before crossing national boundaries.
Walls are one of the most seductive non-solutions available. People persist in thinking that fences make their property more secure, when they often do just the opposite as they provide excellent cover for burglars! They keep dogs in and little kids out, but that's about all. One of the most infamously ineffective walls was the Maginot Line. It is as General Patton said: "Fixed fortifications are a monument to the stupidity of man."