Shaking cocktails serves 3 purposes and the reasons might surprise you.

Ever since the cocktail shaker was invented over 170 years ago, mixologists have adopted them as their primary tool behind the bar. We've all been out to bars where we've seen bartenders vigorously shaking drinks and putting in a lot of elbow grease. Their face says it all - this is hard work that you should leave for the pros! You can hear the ice clanking around in the metal tins and the bartender is holding on for dear life hoping that it doesn't all come apart spraying cocktail ingredients all over the patrons. So why don't they just pour the ingredients over ice in a glass, give it a quick stir and call it a day?
But the reasons for shaking cocktails are simple and they will actually surprise you. There are three purposes to shaking: Dilution, Chilling and Texture.
1. Dilution
If you just poured all the ingredients for a cocktail into a glass and left it in the fridge to cool it would probably taste pretty bad. The flavors would be out of balance with strong alcohol notes. That's because it needs to be diluted - that is mixed with some water. This helps mellow out the alcohol while tying all the flavors together.
When you shake a drink with ice, the ice melts and that water will dilute the drink. This will make it more palatable and tie all the flavors together make a more enjoyable drink.
2. Chilling
No one likes the taste of warm ice cream or a warm smoothie. The same goes for cocktails. By shaking a cocktail with ice, the ice chills the drink to below freezing to give you a really fun drinking experience and to blunt some of the harsh taste of alcohol.
But none of these reasons explain why a cocktail can't simply be stirred. Why the need for the excited and intense shaking and the weird faces that the bartender makes while shaking? The answer may surprise you:
3. Texture

This, by the way, is the reason why drinks without fruits or egg typically aren't shaken but rather are stirred. There's no need to add texture to say, a Martini or a Negroni. Popular drinks that are shaken are Margaritas, Whiskey Sours and Mai Tais.
Now that you know why drinks are shaken, you can also know which drinks need to be shaken and which need to be stirred. You can also be a bit more forgiving when your bartender is making lots of noise while intensely whipping up you drink in a shaker.