The hosts file is used to circumvent DNS. When you type a domain in the address bar, DNS servers are used to resolve that name to an IP address. If you edit your host file with an IP / domain pair, then the domain will always resolve to the IP you defined without using any DNS servers. The way the host file is used to block a website is by pointing it to an IP where there is no such domain hosted, so the request fails.
Here is a fun thing you can do: You can get some hosting in any server and then create a website with any domain you want, e.g. cnn.com or bankofcyprus.com.cy and then add a line to your host file to point that domain to the IP of your server (you don't need to buy any domain). Then when you type that domain to your browser, instead of going to the real website, you will go to your own fake one. This of course will happen on your computer only, not for anybody else.