Where do the stock image websites (agencies) get their images from?
These images (and other media products) are taken or made by photographers and artists around the world. Often, these photographers and artists are professionals who make a living from taking photographs, creating images, etc. But they can also be 'hobby-photographers', casual artists or anyone who has taken a great picture or video, or made a great media product.
When a photographer has an image he or she wants to monetize, the photographer can ask a stock image website if it would be interested in marketing and promoting the image on his or her behalf. The stock image website will normally only be interested in very high quality products, therefore the image will go through a strict quality review process. If the image is accepted, the stock image website will then be hired to market and promote the image to end-users on behalf of the photographer, and the image will be added to that stock image website's collection.
What the image website does is not to sell the image, but to sell the legal rights to use the image. It can sell these rights to one exclusive user, or it can sell these rights to a number of users. If you want to learn more about different licenses, you can go here: Copyrights and Licenses, Royalty-Free License, Rights-Managed License and Extended License.
When a stock image website has been hired to do the marketing of an image, it will enter into an agreement with the owner of the image, where the stock image website is given the right to market and promote the image on behalf of the owner. The stock image website and the owner will agree that any sales proceeds from sales of licenses to the image will be shared in a certain way (for instance 50/50%). The stock image website will then do its best to market and promote this image (as well as all other images) on its website to try to sell licenses to end-users.
The end-users that purchase licenses to these images (and other media products) are normally persons or companies that create websites that need images, bloggers who need images for blogposts, graphic designers that create digital or print graphics, advertising agencies that need media products for their campaigns, news agencies that need images for news stories, etc.
When an end-user, lets say a blogger (who needs an image for his latest blogpost), selects a particular image from a stock image website, he or she will purchase a license to this image. The stock image website will then pay the photographer the agreed share of sales proceeds (in this case 50%), and keep the rest.