My interpretation ...
I think the movie aims to convey a message about goodness, badness, and a mixture of goodness & badness in the world.
1). Clint Eastwood is the "Good." He shows mercy (e.g. lets Tuco live), he shows compassion (e.g. "Sorry, Shorty"), he doesn't kill or bother anyone who didn't threaten him etc. Tellingly, the "Good" is the movie's protagonist, the character that the viewer naturally identifies with. This automatically signifies the movie's idea that goodness is pivotal and desirable in life.
2). Angel Eyes is the bad. He viciously kills two men in the opening scenes, one of whom is on the deathbed, just because "I do what I am paid for." He also kills one of the man's sons. He brutally tortured Tuco. He probably would have killed Blondie / Eastwood, which is why Eastwood seeks escape.
3). Between Eastwood ("Good") and Angel Eyes ("Bad") is Tuco, the "Ugly." Some people say that Tuco should be "Bad" or "Really Bad." But I disagree. Tuco has some sympathetic qualities. The scene with the Padre, the brother, indicates that Tuco ended up bad because he grew up in harsh circumstances, in poverty, with limited opportunities ("you're either a padre or a bandit"). I also consider it a deliberate feature that Tuco is a brown-skinned Hispanic while Eastwood & Angel Eyes are White men, in a society dominated by whites and racism. Tuco is lonely. He is short, physically unattractive. He's also dim-witted (e.g. - he didn't think that Eastwood would give him wrong info about Arch Spencer grave; he didn't realize the Angel Eyes would kill him anyways after giving the name of the graveyard). Tuco's poverty, intelligence, loneliness, and appearance are the reason he is "The Ugly."
Importantly, "The Good" and "The Ugly" survive in the end, leaving with the money. They also work together at several points, showing signs of friendship. Therefore, the movie conveys the message that Goodness and Ugliness can go together, and a person can make it in life if he is good or ugly; or both. Eastwood, obviously, made it out most comfortably and stylishly, so the movie puts goodness as #1. But Tuco's survival, however embarrassing at the end, still means you can be ugly and still be ok.
But badness can't survive. Angel Eyes and Eastwood join together for a little while, but the partnership doesn't last long; in the end, Eastwood kills Angel Eyes. Therefore, the movie declares that goodness (Eastwood) and badness (Angel Eyes) cannot co-exist or cooperate, the way goodness (Eastwood) and ugliness (Tuco) can. Angel Eyes also dies at the end, with shame, and he gets no money. So the movie declares that being bad will not produce good results for the individual in life.