Many municipalities are going to a check valve between the city water supply and your home. Theoretically it isolates any contaminants in your system from migrating into the city's system. Without an expansion tank, when the water is heated and it expands, it has no place to go (except out the relief valve). The expansion tank gives the water a place to go and the relief valve only operates when the thermostat fails.
Ted
To expand on Ted's accurate reply.. Most codes now require a dual check valve, they allow NO backflow. Commercial applications may require a "reduced pressure principle" valve that has a chamber that opens to the atmosphere when the downstream pressure exceeds the inlet. By code, those valves require periodic testing by certified techs with certified testing gear.
The backflow device prevents any thermal expansion from backing out the supply line. The increased pressure can open the T&P valve, and absent that, can create enough pressure in the water heater to crush a flue passage, distend the bottom of the tank to the extent it becomes a "weeble", or in rare cases where an ignorant homeowner has plugged or modified the T&P valve, a runaway heater can flash its contents off into steam and quite literally become a bomb. Superheated water can flash into steam ~1025 times its volume in the flash of an eye. A T&P valve is nothing to trifle with.
The expansion tank absorbs the volume of expanded water. Worth noting is that the expansion tank is installed on the COLD piping. It's not rated for hot water, I've seen lots of improper installs, sometimes they work, doesn't make it right.
Our marine water heaters can benefit from an expansion tank, but the typical presence of a check valve on the inlet of the water heater complicates installation. Since the inlet check's function is to prevent a volume of heated water from backflowing into the cold supply (different function from the dual check), installing an expansion tank on the cold line is ineffective. The reaction is to install it on the hot line, which may work, but can often create more problems. With the potential for very hot water due to engine heating, the tank is subjected to conditions beyond its design parameters with resultant premature failure.
The simplest solution is to modify the check valve by creating a small bypass by drilling a very small hole (<1/16") in the flap, or filing a notch in the seat. This preserves the function of preventing the hot flow into the cold lines, while providing a path for the thermal expansion to find its way to the expansion tank or accumulator if the system is so fitted. If an accumulator is already present and large enough, modifying the check valve may provide enough reservoir to absorb the expansion without the need to add a supplemental additional expansion tank. Plus, the expansion tank can be installed anywhere in the cold piping where it's convenient.
If your T&P valve isn't leaking and you "test it", it will be leaking soon! If it ain't broke.... If a T&P valve is leaking, REPLACE IT with a new one having the same rating as the one removed. They are rated at a temperature, and pressure, with a btuh capacity. A replacement should be of equal rating, and not exceed the working pressure rating of the pressure vessel that it's protecting. The btuh rating must be equal or greater than the btu heating capacity of the water heater. It should NEVER be substituted with a pressure relief only valve. Because...The boiling point of water at 150 psi (typical pressure rating of a water heater) is 358F. If a runaway heater has no thermostatic limit, it can conceivably get to 150 psi and won't relieve. If for some reason that pressure is relieved, the boiling point suddenly plummets and the water at 350F flashes into steam. The water heater has become a bomb.
Not typically a huge concern in our marine applications, but worth knowing the WHY's when the subject of T&P comes up in discussion.