If I had to guess it was so many doughnuts/bagels could be placed on a stick and taken around, eg to be sold, but I’ve never come across this in real life or in media.
There are 2 important functional effects of the hole in cooking. First, it reduces the distance from the surface to any part of the interior. This reduces cooking time, and makes cooking more even. This is important for boiled breads (bagels, pretzels) and deep-fried breads (doughnuts), and for pan-fried breads and breads cooked in very hot ovens. A hole in the middle is not the only way to reduce the distance to the surface - other methods include flat breads (e.g., naan, puri), long thin breads (e.g., Chinese deep-fried breadsticks), small breads (Finnish munkki), dimpled breads (Uighur girde), and multi-strand twisted/plaited breads. Flat breads and long thin breads result in a large product for the weight, and small breads must be small. Toroidal breads are a good solution for having not-too-small weight and not-too-large size.
Secondly, a hole (and dimples, and twists, and some of the other methods above) reduce how much the bread puffs up. Some flat breads puff up a lot when baked or fried (pita, puri), and if this is considered undesirable, a hole will reduce it.
Also, a torus offers a relatively large surface area for the volume, which can be important for breads with coatings (icing, molasses, sesame seeds, etc.).
The holes can be, and are, used for sticks and strings.
Bread vendor in Cairo: https://i.pinimg.com/originals/72/46/36/72463605fa336de59b0c0189089ee05f.jpg
Bagels on strings in Poland: http://blogs.kcrw.com/goodfood/2011/04/street-food-in-poland/
Rye bread stored on pole in Finland: https://commons.wikimedia.org/wiki/File:Ostrobothnian_house_interior_with_rye_bread_drying_on_a_pole.jpg (for long term storage in the home, not for sale)
In many cases, the first reason above is the most important, and the use of sticks or strings is secondary. In the last example above, storage on a pole is functionally important, since it provides excellent ventilation for better drying, and makes the bread less accessible to vermin. Purse-shaped Lebanese kaak bread, with its off-centre hole and large main body: http://mehtapozer.blogspot.com/2013/02/kaak-street-bread-in-beirut.html doesn't gain the benefits of the first reasons above, so use of the hole for carrying (pole, string, or just as a handle) is the main functional benefit.
The bagel enters history in 1610 (i.e., we have written records of bagels from then), in food-related sumptuary laws in Poland (Balinska, 2009). Ring-shaped breads are much older than that, having been baked in ancient Rome and Egypt.
(Dimpled breads were also made in ancient Egypt: (example 1), (example 2).)
Reference:
Maria Balinska, The Bagel: The Surprising History of a Modest Bread, Yale University Press, 2009.