To say they're exempt would be a mis-statement, but there are certain years that are more likely and certain years that are less likely to fail.
Eventually the head gaskets will fail on any engine, the normal service life seems to be around 200 - 250k miles, which tends to be the life of the vehicle. Subaru EJ22 head gaskets tend to make it to 300k and sometimes beyond on original gaskets due to their design.
Any early DOHC 2.5 known as the EJ25D, used most commonly in the Legacy Outback between 96 and 99, is almost guaranteed to have a head gasket failure by 150k miles.There are some rare cases of these where the head gaskets have lasted just as long as on any other engine.
The typical failure mode on these is for coolant to leak into the combustion chamber and be burned away by the combustion of fuel and air.
Generally these can be successfully repaired and the replacement gaskets will last the rest of the useable life of the car. Unfortunately, often the engine is damaged beyond repair because the head gaskets are not replaced at the first sign of failure, and the engines are driven to the point of overheating multiple times, or in some cases severe overheating, causing damage to the bearings in the engine. This results in catastrophic failure of the rod bearings, often causing rods to break and put a hole through the engine block.
The second generation SOHC 2.5 used in almost everything from 1999 to 2004 is susceptible to head gasket failure, but in a different way. These typically leak externally, or towards the outside of the block. It will mean occasional drips or signs of seepage of coolant around he head gaskets on the block. This is a manageable condition through the help of a cooling system conditioner required by Subaru for use in these engines.
As with the earlier design, severe overheating will cause internal damage, but the cases of severe overheating are less common because there are signs of coolant leakage that lead to the driver having the vehicle serviced before engine damage is done.
Of the newer EJ25 varieties from 2005 to current it is hard to say. These have not shown signs of head gasket failure in a widespread manner, but most of them are still below the typical failure mileage. A dealer will be the best informed of how these are holding up, because that's the first place owners of newer vehicles will go when their car has a problem. But so far, they seem to be much less problematic than the earlier incarnations of the 2.5.