Showing a difference perspective
Something that villains can do in your story is to show a different perspective about what your heroes and audience hold as important and true. Your heroes always stand for something, they have ideals and a certain view of the World and how things should be. And there is always an opposite view to that which can be explored. Having this different perspective is what is giving depth to the ideals and truths your characters defend. If your heroes stand for peace but your world does not contain war and conflict and villains who convincingly represent war and give their best effort towards it, then there is no possibility to explore why peace is better than war and to have intensity in the story. Sometimes, villains also bring a deeper perspective and show a better way or prove the validity and worth of their ideals against an even bigger evil.
Exploring our shadow
Another important function of quality villains is for us to experience our shadow. All of the parts of ourselves that we like to repress, the unpopular opinions we hold. These are things that we can subconsciously feel through good villains. They stand up for unpopular feelings with strength and stand up for themselves. They are showing the parts of our character we do not like to assume such as wanting power, getting revenge. Eveyrthing that we do not like to show or to assume we have. This is also why so many villains are very attractive to the audience. They may not be moral in or represent what the audience believes in but they probably display power and strength or other things that the audience can identify with.
Strengthening the Hero
Another important aspect of villains is that without them, there would be no conflict, no reason for the efforts of heroes and nothing to stand against. Every evil action they take is an occasion for protagonists to stand up agaisnt something. And they are creating the challenges that heroes have to face in order to grow and develop. Whether they are actual characters or concepts such as nature, human nature or an artificial intelligence, villains give the context for showing and developing qualities such as strength, honor or kindness.
This is why quality evil and villains are capital to any story and why you should spend a lot of time working on them. They will make or brake your story. The quality of your heroes and the emotions they experience and produce in the audience will be depending on the quality of your villains. Nobody can be a hero fighting poor evil.