Why do websites make you type the codes shown on the screen?

To stop automated downloads or spam and sometimes to annoy people and persuade them to pay for an account on the site.