No one said that TOS's override the law.
If you shout something in public, someone might hear you. If you shout in a locked house they won't hear you unless they break in.
If you post something publicly on the internet, then people can look at it. If you post something privately on the internet, people have to agree to your terms to view it.
That's it, that's the logic the government uses to allow website scraping.