Browser manufacturers receive reports from users of known malicious sites, and use that to form a blocklist. The browser downloads a copy of the block list and compares it to the URL of the page you're going to.
Only then does it show a big scary red warning.
Search engines are known to do their own work in removing malicious sites. They aren't perfect and some do fall through the cracks.