The IRS defines “emergency personal expense" as an unforeseeable or immediate financial need relating to necessary personal or family emergency expenses. (Section 115 of the Secure 2.0 Act)
An emergency will allow you to make a withdrawal, still subject to tax, but without the 10% early withdrawal penalty. You can take one financial withdrawal emergency per year, not to exceed $1,000.
Would replacing a leaking roof which is making the house unhealthy due to black mold be considered a hardship or emergency.
This is a situation in which if you are audited, then you will have to defend your position that it was an "emergency".
I suggest you get documentation from roofers and code enforcement agents who will state in writing that this is a health hazard. Actually having the city cite you for violating some city code would be perfect.
There is no hard-and-fast rule here.