How to use a lens hood should be photography 101, yet I've met serious amateurs and enthusiasts, good photographers to be honest, who didn't really know why a lens hood should be used or when to take it off.
So let's make things clear on that one. Lens hoods, those plastic weird-looking things that go on the front of your lens, come in all shapes and sizes. Typically they used to be supplied only with expensive lenses, but today even the most basic plastic kit lenses come with a dedicated lens hood.
(Success Tip #2:The secret to selling more photography with less effort)
There are two main purposes the lens hood has to serve. Number one is protection, at least in my book. A lens hood will save you from a lot of unexpected and certainly unwanted events and incidents that involve some kind of impact between your lens and something hard. Let's say you're shooting your son's soccer game with a 70-200 mm f/2.8 and a kick sends the ball in your direction at a really high speed. Not having a lens hood on would definitely cause massive damage. Forget about the UV filter. Even a premium one won't help you in case of direct impact with a fast ball and even if the ball doesn't touch the front element of the lens, the fragments will most likely damage it. So the first purpose of the lens hood is protection.
Its second goal is to keep unnecessary light from entering the lens. The best way to see how this works is to take two separate photos, with the same framing and settings. Keep the lens hood for one shot and remove it for the other. You'll notice how the contrast and saturation are visibly stronger in the shot taken with the lens hood mounted and how the flare is reduced or completely eliminated. It basically works the same way as holding your hand over your eyes in powerful sunlight to reduce unwanted light.
So in a nutshell, this is why using a lens hood is good. Here's a more detailed explanation from steeletraining.