The primary purpose of a lens hood is to prevent unwanted light from entering the lens that would cause lens flare ('extra' lights and/or internal reflections within the lens itself). Indoors and outdoors, whereever there are multiple sources of light, especially lights off to the side that are not in the picture may cause lens flare. Under most of these situations, the lens hood 'does its job' and prevents these flares.
The lens makers go to great lengths in designing their lenses to prevent lens flare, including various coatings on the elements themselves. But even the best of lenses with hoods in place cannot prevent certain flare situations. About a month ago, I was taking pictures of a big band with nothing more than their individual music stand lights for illumination. Perhaps 5% of the pictures had lens flares caused by these small lights, shining at an angle into my lens. Fortunately, as I took pictures from many angles, I simply trashed the pictures with lens flares...except for one, that I managed to Photoshop the 'ghost' light out of the picture.
Another advantage of using the lens hood is protection from bumps, bangs, dings, and even some 'drop' protection. Having longer lenses and working indoors, I know I'm prone to bumping into everything from people to walls, tables, doors, etc with my lens while I'm moving around taking pictures. So my lens hoods have a number of dings and scratches in them. While $20 or more to replace a broken lens hood may sound like a lot, it's cheaper than replacing an entire lens or even the filter thread area on a lens. And a new hood is also less costly than replacing a front element from the damage done by a broken 'protection' filter.