The home-building industry had been one of the stock market’s best performers of the year until recently.