You leave the tracks right in the first sentence. There was nothing whatsoever illegal about the order.
There is nothing illegal about ordering a Chaplain not to pray while in uniform.
I might be a little rusty on the UCMJ but I don't believe that anywhere in it does it forbid the free and open practise of religion in the military.
Please Correct me if I am wrong.
The same holds true for the U. S. Constitution.