There’s nuances around things like divorce, but people overlook just how tax advantaged traditional investments currently are.
I’ve seen far to many people lose thousands and some tens of thousands by doing so.
People only need to crack open the piggy bank when shit hits the fan. During those times (layoffs, etc.), the value of what's in the pig is probably depressed to begin with. So your hypothetical scenario is actually worse than you're suggesting, since you pay a 10% penalty on depreciated holdings.
If you legit need the 401k money, they do allow some circumstances for hardship withdrawal penalty free. You just have a higher tax liability that year.
But yes, don't use your 401k for general savings. Depending on your credit you are better off taking out a loan against it.