First the hitboxes interact, and that's like a frame.
Then, depending on how strong the interaction is, there's frames called "hitlag". This is where the characters are frozen in place for several frames, doing nothing, due to the hit.
Then, after however many frames of hitlag, the move finally sends the opponent on some trajectory.
Which direction you are going for your trajectory is influenced on the direction you are holding when you finally get sent some trajectory. It doesn't matter if you have been holding this since the match started, or if you input it at the last possible frame.
However, one thing that can happen is that during the "hitlag" where characters are otherwise frozen in place, if you put in a directional input, it will move your character that direction (AKA Smash DI). EX: You get stomped by Ganondorf while in the air. You pushed right during hitlag. Your character goes to the right. You then let go of any directional input before hitlag is over -- you end up having no directional influence, but your "starting point" is to the right of what it was originally.