If the ball is deflected from the bat onto the batsman's legpad and then gets caught by the keeper, are they out, if the ball does not touch the ground before it is caught?
Out caught. Quoting Law 32:
The striker is out Caught if a ball delivered by the bowler, not being a No ball, touches his bat without having previously been in contact with any fielder, and is subsequently held by a fielder as a fair catch, as described in 3 below, before it touches the ground.
There is no mention in any of Law 32 that means a catch is not a fair catch if it touches the batsman's pad.