Would a holocaust in the us that killed six million jews be legal as long as it was justified using existing legislation such as national security? Would any attempt to change these laws afterwards to convict the holocausters be an ex post facto?
As law is understood in the overwhelming majority of nation-states: No
What is at the heart of your question are two competing schools of jurisprudance:
Natural law: which holds that "law" is independent of any given political order; law exists "out there" and can be "discovered" but not "made". Laws should follow moral principles. It follows that any putative law that contradicts natural law is no law at all. Under this philosophy, something like the holocaust would never be legal.
Legal positivim holds that laws are made by humans and that there is no necessity for the correlation between law and morality. That is, a morally "bad" law is still the law. Under this philosophy, something like the holocaust would be legal providing it was enacted and carried out in accordance with the law.
Which school of thought is ascendant varies with time and place and you will get different answers if you compare, say, modern Germany and modern China, and Germany in the 1930s to the 2010s.
Under the current system of international law as currently articulated (although not necessarily as enforced) by the UN; a holocaust type event would not be legal irrespective of local law.
It is worth noting that the holocaust was "legal" under the law of Nazi Germany, however, that was not an argument with which any defendant's had any success in the post-WWII war-crimes trials.