The background images for a game in your library (and also for the game's store page!*) are taken from the publisher / store page † and your gallery of recent screenshots.‡
* If no background image was specified by whoever made the store page, it simply chooses the right-most screenshot from the game's gallery. Methodology: Looked at very old games on steam, then some new / popular games. Results held up to prediction on every case attempted.
† Images are taken from the store page only in the case that no images have specified by the publisher, that is.
‡ Methodology: I have some old pictures of The Guild 2 in my gallery, about half a year old. After clicking back and forth for new images in my library about 30 times, they've yet to show up as a background for the game.
To see if a newer picture would appear as a background, I loaded the game, and took a screenshot and uploaded to the cloud. It showed up the first attempt.
Similarly, taking another screenshot without uploading to the cloud also resulted in that image being posted as a background on first attempt.