It depends on the level of computer integration you are willing to deal with. Mechanically the EJ engine ran till 2012 in the Legacy and could be had with a 6 speed manual. Those do tend to have fire ring head gasket failures and sometimes dropped valve guides but if you correct those two issues they are mechanically pretty sound. The CANBUS and the electrical system.... as long as you don't keep the car past about 200k it will probably be alright. Don't get anything with a sunroof and if it's ever been in a flood just forget about it.
As for non-CANBUS cars - 2005 and some 2006 is about the last years. They have some issues with drive by wire, airbag indicator/dome light circuit boards, bad HVAC/radio solder joints, head gaskets weeping oil, manual transmission center differential and rear input shaft bearing failures, and the last few years we are seeing a more engine computer failures either causing really bad misfires due to ignition coil driver failures or phantom misfire codes that aren't real misfires but require the computer to be replaced to stop them from throwing codes.
The problem is starting to be that older Subaru's that are actually reliable and would otherwise be desirable are suffering from parts availability. Engine ECU's for the 2005+ models have the VIN number coded into them and can only be programmed one time so you can't easily use a used ECU from the junk yard - and Subaru is actively discontinuing the parts - there's already models that you can't buy a new ECU and a used one will not work due to registration issues, etc. At some point it becomes a real problem. And then there's the availability of drive axles, etc - can't get any axles for 2004 and older from Subaru now. And aftermarket are absolutely trash.
GD