Attacking during a race when your competitor has a mechanical failure?
It's just considered to be bad sportsmanship to take advantage of another rider's mechanical problem. The underlying idea is that, as much as possible, the race shouldn't be determined by random strokes of bad luck. It should be won and lost based on riders' strength, bicycle handling proficiency, as understanding of race tactics.

It is not technically illegal to attack in this situation. Had Aru continued the attack, most likely the other GC contenders would have followed, but openly chastised him later. 

That scenario actually happened at the 2010 Tour when Contador attacked while Andy Schleck was dealing with a dropped chain. Contador stated afterward that he was in a group, the group was going hard, and he didn't know about Andy's chain issues. Other riders and commentators said that he shot past Schleck so fast that he must have known something was wrong and roundly criticized him. Whatever the case, Contador took the yellow Jersey that day and held it until the end for the overall win. (CAS later found him guilty of doping, stripped him of o the title, and gave it to Schleck who had come in second, but that's a different story.)