Your fence has to extend deeper than they can dig.
This is why you have an army in North Gaza. This is assuming Hamas will still be around in South Gaza after the war.