They were hung to death for avenging the murder of Lala Lajpat Rai, (a Hindu Mahasabha founder member). It's believed Gandhiji could have stopped their hanging, so why didn't he ?
Bhagat Singh was only 24 when he was hanged. It could have been stopped by Gandhi. But Gandhiji was not sincere in his efforts for reasons of his own. Gandhi could have put pressure on Irwin to release Bhagat Singh. Irwin & Gandhi were very close. So close that Irwin had forced a temporary truce on the freedom movement. However, he sent S Shastri, T B Sapru & M R Jaykar to plead wih Irwin.
Gandhiji seemed to believe that if Bhagat Singh lived on, his idea of "non violent" movement would get challenged. So it is alleged that he did not do enough to stop their hanging.Gandhiji, in fact, told openly that militant movement was harmful to "India's freedom movement".
Although Gandhiji, on popular pressure, did write to Irwin on the day of the execution, pleading to have mercy on the three revolutionaries but as anyone would expect - the letter would be too late.
Some believe Gandhiji was mortified that the revolutionaries of India had rattled the British. Moreover, and more importantly, revolutionaries had shown to Indians that the colonial rule could be overthrown by force and bravado. Apparently that was not acceptable to Gandhiji (So much so that his role was criticized in the 1931 Congress Session by congress itself) who vehemently advocated non-violent means for achieving the dominion status for India ( There is a belief that, GandhiJi was happy with dominion status. Rise of the revolutionaries and aggressive campaign by the rising Garam-Dal leadership forced him to campaign for "Poorn Swarajya" (Total Independence).
Also, as one would expect - Nehru played a key role in further pushing Gandhi in not taking a hard stance against the execution of Bhagat Singh. Nehru too was afraid that militant movement in the Congress led by Subhash Bose would overtake him & Gandhi- and reducing them to irrelevant members. So Nehru did what was necessary for safeguarding his political interests. Irwin knew about the power struggle between Bose & Nehru-Gandhi. Irwin told Nehru to ask Gandhi to go soft on the execution. That is the story of how Gandhi & Nehru became complicit in getting Bhagat Singh & Comrades hanged by the British.
Gandhi later said, "Rajguru, Sukhdev and Bhagat Singh did not wish to live. They refused to apologize, or even file an appeal."