Have you checked the N-R Lock solenoid?
Sounds like this is dickie?
It is mounted in the Gear Selector Control System.
Page CS-16 in the Workshop Manual
We’re the best Subaru Forester Owners Forum to talk about the best years of the Subaru Forester, modifications and reliability history of the Subaru Forester.