It would be legal, unless you had an employment contract (including a union agreement) either protecting your employment or limiting the reasons for which you could be fired. Without a contract of some kind, employers are generally free to fire employees at any time, for any reason--including for things they've done in the past.