If the wicketkeeper removes the bails, but keeps them in their hands, is it out or not?
The wicket is down and the striker is out, Stumped.
From the Laws of Cricket, Law 29 The Wicket Is Down:
29.1 Wicket put down
29.1.1 The wicket is put down if a bail is completely removed from the top of the stumps, or a stump is struck out of the ground,
220.127.116.11 by a fielder with his/her hand or arm, providing that the ball is held in the hand or hands so used, or in the hand of the arm so used.
29.1.2 The disturbance of a bail, whether temporary or not, shall not constitute its complete removal from the top of the stumps, but if a bail in falling lodges between two of the stumps this shall be regarded as complete removal.
with emphasis added.
This makes it clear that the wicket is down at the moment the bail(s) have been removed, provided such removal is permanent and not merely a “disturbance”.
Law 39 Stumped then only requires
39.1.1 The striker is out Stumped, except as in 39.3, if
a ball which is delivered is not called No ball
and he/she is out of his/her ground, other than as in 39.3.1
and he/she has not attempted a run when his/her wicket is fairly put down by the wicket-keeper without the intervention of another fielder. …
that is, the requirement that the wicket is put down has no further conditions beyond the definition in Law 29.
There is never a requirement that the bails go anywhere particular, or in fact that they be removed, or that they are even present at all.
If a bail is removed, it does not matter where it goes next, as long as it’s not simply back onto the top of the stumps.