When the engine is decelerating, it is trying to slow down, but the wheels are still trying to move forward. This causes the engine to rock back and forth, which can put stress on the engine mounts. If the engine mounts are worn, they will not be able to absorb the shock of this rocking motion, and it will cause a loud knock.
When the engine is accelerating, it is moving in the same direction as the wheels, so there is no rocking motion and no knocking sound.