That's ... innovative, a "tax law" arbitrage of sorts. With regards to the critics pointing to the "wash sale" rules, and limitations on shorting in tax-deferred accounts, these can be circumvented by trading ETFs. For example, go long the bear ETF (such as SDS) in the 401K account, and go long the same dollar amount of the bull ETF (such as SSO) in a brokerage account. If the market goes up, you've effectively transferred money out of your 401K and avoided paying the early withdrawal penalty, which I think is a hefty 20% penalty.
The problem is, of course, that the effect could easily be the opposite of what you intended. If the market goes down in the example above, then you've contributed to your 401K, instead of withdrawing from it, which was the intent.
With regards to the legality of this scheme, I don't see any issues.