Put simply, 401(k)s are meant to be retirement accounts, meaning that the money is ideally supposed to be used when you reach retirement age. The early withdrawal taxes that 401(k)s and IRAs use are supposed to incentivize you to leave the money untouched until you reach retirement age.
However, hardship withdrawals do exist to allow you to borrow money early under extenuating circumstances.