Well, that’s why we have courts, so individual controversies are solved - determining things like whether the particular electrified sign in question is dangerous enough to be considered per se illegal. Might be a close call, but generally I think courts frown on devices rigged to hurt someone especially if there is no warning sign.
Maybe the point is prudence would be on the side of putting up a warning sign. Otherwise it might be argued you wanted to see the guy trespass and attempt to steal so you could hurt him.
Come on, shake! It'll only hurt a little!
Even a fool knows to look both ways before crossing a busy street.