There is not an IRS early withdrawal exception for a personal hardship. Nor is there an IRS early withdrawal exception for the purchase of a personal residence when the funds are withdrawn from a 401(k). The withdrawal is a taxable event and the taxable amount withdrawn is entered on your tax return as ordinary income and taxed at your current tax rate. If the withdrawal was made before you were 59 1/2 or you were not separated from your company that held the 401(k) and under the age of 55, then there is a 10% early withdrawal penalty assessed on the federal tax return, entered on Form 1040 Line 59 as a tax liability.
See this IRS Tax Topic for early withdrawal exceptions from accounts other than an IRA - https://www.irs.gov/taxtopics/tc558.html
Wouldn't the extra tax be offset by the benefits from buying a home in that tax year?
@jeeptjrcon - There is no direct tax benefit by purchasing a home. If you can itemize then you "might" be able to deduct any mortgage interest and property tax paid, but that is true reguardless of where the money came from to purchase the home and has no direct relationship to a taxable 401(k) distribution and the early distribution penalty.
If all the purchase money came for the 401(k) and there was no mortgage then nothing other than any property tax paid would be an itemized deduction, so the taxpayer probably would not be able to itemize and could not deduct anything at all.