There are a few options when this happens. One is extending the closing until the work is done, which is usually not preferable. Another is reducing the purchase price by the amount that the work is expected to cost. A third is arranging for the seller’s lawyer to hold back approximately what the repairs are expected to cost, with the buyer able to apply for reimbursement out of that fund as the repairs are done.
The best option is the one you are most comfortable with, but always check that the repairs are done before closing as it’s very hard to get reimbursed if you’ve let the money go.