The U.S. shale boom has for years blessed chemical makers with cheap energy, prompting record spending on new factories. Now that unchecked growth is costing the companies big.