Is it an IRA or a 401k or both. There can be different exceptions to the penalty depending on the plan. While your employer may permit a hardship withdrawal, it is still a taxable event.
Pension and IRA
There is an exception for pensions that relates to medical expenses. You do not pay a penalty on any medical expenses for you or your dependent that are over 7.5% of your AGI.
IRA only
Distributions made because you are totally and permanently disabled.