It's because the fundamental issues causing the layoffs should already be priced into the stock (due to poor earnings reports and such). So layoffs are considered a good response to the fundamental issues and cause a price increase.
Stock price respond to changes, especially unexpected changes (expected ones are mostly priced in) and new information.
The short term price increase is not a sign that investors think the company is doing good (or bad) generally. They already have an opinion and it is already priced in. This is ("theoretically") a sign shareholders agree that this is the right thing to do. It's not uncommon for share prices to rise following news of layoffs. Companies don't like to fire. They usually err on the side of not firing (even when necessary). So, this suggests management doing hard, presumably necessary stuff.
Lower costs mean higher profits. Lower # of employees gives them greater flexibility, they can hire contractors where they need them and eliminate positions where they don't.
the layoffs were probably factored in already...and they were probably expecting a higher number...so if the number falls below street expectation the stock price goes up
Thanks