Some building codes require them. Typically they're to be used with tankless water heaters. When the hot water is trapped in the line, it may push back on the faucets or the water heater. The expansion tank will help reduce wear on both.