First: that's not what a "sanctuary city" is. That term specifically refers to cities that don't let their local law enforcement and courts assist ICE/CBP. The idea is that local crimes happen to everyone regardless of immigration status and we don't want a situation where undocumented people live lawlessly because they can't talk to police or court officers without fear of deportation.
Second: there's no "activist judge lets you go" loop. In practice judges are pretty tightly constrained by the law when it comes to pretrial detention. However, there _is_ a "cops refuse to do their job out of protest" loop.
And also: none of this is a technical problem! It's all political/social dynamics and surveillance doesn't affect it at all.