While marth's and roy's are altered at the moment of input. So for them trajectory and the way they face are inputted simultaneously
Not necessarily true. You can input an up-B with Marth and Roy using directly up on the control stick, but during the beginning frames you are able to change the trajectory by moving the stick to a different angle. You can notice this stuff really easily if you mess around in Training Mode on 1/4th speed.
To OP, I'm pretty sure it's character dependent. I think most character's have at least a couple of frames during which they can input a turnaround to change which direction they're facing, but I also think some characters can't turn around at all. I'm pretty sure Link, Young Link, Bowser, and DK are all incapable of actually changing which direction they're facing, but they can grab the ledge from either direction as long as they are by the ledge before their up-B completely finishes.
Your best bet is to check the character specific forums for the Hitbox and Frame Data thread and look for the up-B animation. Most threads should specify exactly when the up-B ends and how you can grab the ledge during it. Then ofc practice on your own like debaser suggested.