I also have a 2005 Legacy wagon and the rear hatch will not lock. On inspection I found the wires within the rear rubber accordion boot had torn themselves apart on the passenger side . WTF
I have filed a complaint with /www.nhtsa.gov (NHTSA) and suggest others do the same.
When the wires tear you also lose your high mount 3rd brake light in addition to not being able to lock and secure the rear hatch.