Yes, it is legal. Sorry it happened to you!
There are typically several reasons an employer would do this.
1. They just don't have the work to keep you busy.
2. They just can't afford to keep you employed
3. As hotrod stated, they are looking for ways to make you quit so they don't have to pay unemployment. (although, if they really wanted to make you quit, there are other ways to go about it.)
It's not fun to have that happen, but if their reason is 1 or 2, the decision was probably a sudden one and they were unable to give anyone notice. It sucks, I know!