It's happened before.
https://www.oyez.org/cases/1940-1955/343us579
A court battle is much guaranteed.
https://www.nytimes.com/2019/01/07/u...emergency.html
One theory I've heard from conservatives skeptical of Trump is that he'd do this to get political cover with his base, and then blame others when the courts rule against him. "I tried my best but this is why we need more Republicans in Congress."