Even today, this question is one on which historians differ based on their political beliefs.
For liberals, there is a strong feeling that Sacco and Vanzetti were convicted and executed because of prejudice against immigrants and radicals. In this view, Sacco and Vanzetti were not given a fair trial because people distrusted immigrants and anarchists. They were, according to this link, convicted and executed "because of their political beliefs and ethnic background."
For conservatives, this argument does not hold water. Conservatives believe that the two men were guilty and that subsequent claims of their innocence are made because they fit the liberal historical view of the 1920s. For example, in A Patriot's History of the United States, Schweikart and Allen, say that there was "solid evidence" against the men and that claims of injustice have "not stood up."
This question, then, is still subject to debate, though the mainstream of historians would tend to argue the two were punished more for who they were than what they did.
Most historians would tell you that Sacco and Vanzetti were punished more for their beliefs than anything else.
Following World War I, there was a tremendous desire in America to return to "normalcy," a vague term used to describe ideas of American culture before the war. This desire for "normalcy" was exacerbated by a growing sentiment of the superiority of those of Anglo Saxon ancestry and the threat posed to that superiority by peoples who were naturally "inferior." Among the pseudo-scholarly works which promoted this idea were The Decline of the West by Oswald Spengler, and The Passing of the Great Race by Madison Grant in 1916.
Bombings and other activities deemed terrorists were increasingly associated with foreign born radicals. The fallacy soon developed that the only people capable of terrorist acts such as these were those who were foreign born, particularly people from Southern and Eastern Europe. Sacco and Vanzetti were charged with a bank robbery in Braintree Massachusetts which had resulted in the murder of two people. Although there was substantial evidence of their innocence, the prevailing sentiment was that because of their ethnicity, they were probably guilty. They apparently were convicted not because of evidence of the crime but rather because of their political ideas and ethnicity. The Trial Judge referred to them as "those anarchist b---ds. Efforts to provide justice for them failed, and both were electrocuted.
The best way for you to answer your question would be for you to dig a bit. University Press of New England is publishing a book, In Search of Sacco and Venzetti, written by SUSAN TEJADA is a journalist and writer, serving as an editor at the National Geographic Society for many years and as editor-in-chief of World. Tejada has spent years investigating the case, sifting through diaries and police reports and interviewing descendants of major figures. She discovers little-known facts about Sacco, Vanzetti, and their supporters, and develops a tantalizing theory about how a doomed insider may have been coerced into helping professional criminals plan the heist.