It's legal for Americans to serve in foreign armies for the most part unless obviously they're against American interests. It's just discouraged in most cases.
The lead up to WW2 was different because we were pursuing an isolationist policy. I'm not sure if there was a shift in legal codes or...