As a matter of principle, the fact that a government officials actions are legal does not mean they should be immune to criminal prosecution.
I'll give you an extreme example to illustrate the point:
Imagine Congress passed a law that said the President could rape anyone he wants and the Supreme Court declared it Constitutional.
Even though rape by the President is perfectly legal, the President should still be put in jail for committing rape. Also, every Congressman who voted for the law should be put in jail.