You need to do a relearn process. Instructions below. An 06’ legacy is a ”throttle by wire” car, which requires this procedure. You have a popular car channel, you could figure this out on google.
1) Turn off the lights, aircon, stereo or any system in the car that draws extra current on top of the engine.
2) Disconnect the battery for 30 mins.
3) Reconnect the battery.
4) Before you start the car for the first time, turn the key to the ON position but do NOT turn the engine over. Wait 10-15 seconds so the electronic throttle body or IACV has time to go to the factory programmed home position.
5) After waiting, start the car and let it idle without any load, lights, A/C etc.
6) Every 20 seconds or so the idle will be adjusted up and down as the ECU tries to adjust it towards a stoichiometric fuel / air mix.
7) Leave the engine running for a full 10 mins but DO NOT TOUCH THE ACCELERATOR during this time or turn on anything that will cause extra electrical current draw.
8) Turn off the engine, and leave the key in the OFF position for at least 20 sec.
9) As per step (4) turn the key back to the ON position for 10 – 15 sec without actually starting the engine.
10) Start the engine and leave to idle for a further 5 minutes without touching the accelerator and without turning on other systems in the car.
11) Turn off the engine again and wait at least 20 sec before restarting.
12) Take the car for a test drive as the ECU should now be fully retrained.