Defending Taiwan from a Chinese invasion would be illegal because Taiwan is not a member state of the United Nations?
I suppose that is true. Legally speaking.
But that does not make defending a free people from conquest by an autocratic state that denies its subjects freedom would be a bad thing to do.
And if the legality is your only standard, please explain inaction in response to Russia's conquest of Crimea when Ukraine is a member state of the UN (and also a founding member).
Actions are not necessarily bad because they are illegal.