Originally, film formats were arbitrary and specific to each camera model. For example, Kodak started making "pocket" cameras in 1895, but each new design used a different format. By 1908, they decided to simplify the confusion with a numbering scheme, calling that first format "101" and continuing the numbering up from there. In fact, the "120" medium-format film still in use today is part of this sequence. ("135" for 35mm film came later, and it appears they skipped ahead to make it match.) 101 happened to be square; 102 was 3:4, 103 and 104 were 4:5 and 5:4; 105 is 9:13, and basically arbitrary weirdness continues down the line. By 1916, Kodak had thirty different lines with a dozen different aspect ratios, all in production.
And of course, it wasn't just Kodak — everyone did their own thing, possibly partly to avoid Thomas Edison's patents (as he was famously litigious). Eventually (possibly as that fear receded), some standards did emerge, but even within those, there's a whole lot to choose from. Here's some of the more common formats today, and a bit about their histories.
4:3 is the most common ratio for compact digital cameras, including point and shoot models. It matches the standard ratio of computer monitors in the 1990s as digital cameras were first developed, and that came from TV, which got it from cinema.
Thomas Edison's lab chose a 4:3 ratio for silent film, and it became the standard. No one knows exactly why this particular ratio was chosen, but there's plenty of speculation. One story suggests that engineer William Kennedy-Laurie Dickson asked Thomas Edison what shape he wanted each frame to be, and Edison held his fingers in approximately a 4:3 shape, saying "about like this".
When soundtracks were added to motion pictures, the space required changed the standard slightly, but 4:3 was still the foundation. That translated to television sets, and then to computer monitors, and therefore was a natural choice for early digital cameras, and of course continues to today.
However arbitrary (or inspired?) Edison and Dickson's choice might have been, there's precedent in visual arts — analysis of several different datasets generally shows that the most common aspect ratio for paintings is something close to 4:3, with 5:4 also popular.
This is also roughly the proportion of a "full plate" (or "whole plate") used in Daguerreotypes or tintypes, from before cinema. This format is 6½"×8½", which is roughly 4:3, give or take the oddness of the half inch. Cutting this various fractions was also common, and although the resulting sizes were not consistent, the smaller sizes usually stayed to approximately-4:3 aspect ratio.
Wider formats eventually came to cinema largely as a way to distinguish the attraction of theaters from home viewing. See this for more, or search for "Academy ratio" and you'll get lots of information. This comes back around to photography when we get to the 16:9 aspect ratio discussed below.
It's worth observing that 4:3 and 3:2 are geometric cousins, since halving or doubling a 4:3 frame (in the sensible dimension) yields a 3:2 frame, and halving or doubling 3:2 yields 4:3.
110 film, an obsolete cartridge format for mass-consumer-level cameras, uses a 13mm×17mm frame, which is close enough to 3:4 in spirit — although oddly the standard prints are 3½"×5", or 10:7, a "weird" ratio partly between this and 3:2.
3:2 is the format of 35mm film and the de facto standard for digital SLRs. Oskar Barnack of Leitz invented a small camera using cinema film rolls, and chose to use a double frame — and a double-4:3 frame is 4:6 — which is to say, 3:2 when you turn it 90°. This is the origin of the 35mm film format, and here we are today.
(Beware when searching for more on this; there's an oft-repeated article out there full of unwarranted golden-ratio mysticism. Not only is 3:2 not even close to the golden ratio, but, as noted under 1:1 below, historically artists have shown a preference for more-square formats which are even further from the golden ratio.)
Japanese camera makers Nikon and Minolta used a 4:3 format in their first 35mm film cameras, but then switched to 3:2 along with everyone else — possibly for political reasons, but possibly just for convenience.
When the Advanced Photo System standard was invented, "APS-C" was defined to follow this Classic aspect ratio (in a smaller size). APS also defined APS-P (a 3:1 panorama), which didn't really catch on; and APS-H, which is close to but not exactly 16:9 (but probably chosen for its similarity).
1:1 is, of course, a square. Squares are obvious, and nice to compose in. There's no concern about "portrait" or "landscape" orientation. The inherent symmetry can be used for strong formal composition. So, conceptually, this is pretty straightforward.
However, it appears that the various non-square rectangles were more common for photography — perhaps following preferences in painting, where off-square rectangles are historically predominant.
Square wasn't really a hit until Rollei's twin-lens cameras came along in 1929. These use a waist-level finder you look down into, and it'd be inconvenient to have to tip the camera for different orientations. Hasselblad followed suit with their waist-level SLR, again using square format. It seems that despite what appears at first to be obviousness for composition, square photos were first a matter of technical practicality rather than aesthetics.
Also on a technical note, new photographers often wonder why square sensors aren't used to capture more of the image circle projected by camera lenses — after all, a square is the greatest-area rectangle that can fit in a circle. But, it turns out this is only efficient if you want a square in the end, of course not everyone wants that.
I should mention popular smartphone apps here, too. Hipstamatic for the iPhone was the first to take off, and now Instagram boasts 60 million square-format photos per day. As these are shared on social media to be viewed on "tall" smartphones and "wide" computer screens alike, the appeal is no surprise.
5:4 is a common large format aspect ratio, both as 4"x5" and 8"×10", and that's where the popular 8"×10" print comes from. I'm not sure why exactly it was chosen, but I wouldn't be surprised it simply fits with the historical preferences for almost-square frames as noted above. It certainly goes back to at least the 1850s — see the bit on cartes de visite below.
Mostly, I imagine the history here roughly mirrors the history of standardized sizes for letter paper.
5:7 is another aspect ratio one commonly sees available for prints and in pre-made picture frames. It was a moderately-popular large-format option which seems to have mostly fallen out of favor, perhaps because it's "too in-between" — inconveniently large to enlarge, smaller than people might prefer printed directly. I found a couple of interesting articles on the format (here and here), but I haven't found any particular reason for the aspect ratio; it seems to just have been an acceptable arbitrary choice between the other common sizes of 4"×5" and 8"×10".
Since 8"×10" can be cut in quarters for 4"×5", it seems logical that half-sized film would also have been common, and indeed cameras using the 5"×8" format also exist/existed, but for whatever reason never got to be as popular as 5×7.
This is particularly interesting because 5:8 is a very close approximation of the golden ratio, and maybe this is an argument against people's natural attraction to that. (See this 1891 article, where the author says: "I would recommend the 6½×8½ in preference to the 5×8, since for most work the latter is not so well proportioned.")
One common format with this aspect ratio was popular in the 1860s — the carte de visite, a 2.5"×4" "business card". There was a technique for taking eight such photographs on a single 8"×10" plate, which explains the aspect ratio choice, although especially given the timing it may well be that the golden ratio played some part. This format, though, was supplanted in a few decades' time by larger 4:3-ratio cabinet cards.
6x7 is a common medium-format film format, but this isn't really the aspect ratio used. Unlike typical large format film, this is measured in metric instead of inches, so 6x7 is actually a smaller format than (for example) 4×5, although that's only tangentially relevant to the aspect ratio discussion. The important thing is that the usable portion of 120-format roll film is 56mm wide, so 70mm gives a 4:5 (8:10) aspect ratio. That means you can create 8"×10" prints without cropping, and for this reason, this was marketed as "ideal format".
There's other common ways of dividing up that same roll, giving different aspect ratios, and most of these are already discussed: 6×6 is 1:1 (56mm×56mm frame size), 6×4.5 is 4:3 (56mm×42mm), 6×9 is 3:2 (56mm×84mm). And 6×17 (almost 3:1) is used for panoramas.
16:9 is the standard for HDTV, of course, and it was simply selected as a compromise format by the committee designing that standard. Hooray for committees! This forum thread goes into the background of the decision, but really, committee compromise sums it up — it's not ideal for either the classic ratio or common widescreen formats, but sits in the middle — either awkwardly or conveniently, depending on your biases. Many computer monitors, laptop screens, and even phones use this aspect ratio today, and it's no surprise that digital cameras often offer it as an in-camera output choice to match.
It'll be interesting to see how long this one lasts in the grand scheme of things.