I think Gandalf had to make a judgement call on which event had potential to do the most damage. It was by no means certain at that stage that Aragorn would win through, and a Gondor who's ruler had just killed both himself and his heir would have been well demoralised. All Gandalf could do was take control of specific (shorter-term) situations - the people of Gondor may have looked to him to rule and order things, and that he could not do. So in the end I don't believe he had any choice but to do what he did, irrespective of any moral ambiguity that may exist in the act.