This works because the scammer does not put the phone down. Until the person making the call has put their phone down the line is still open (this is a legacy thing left over from when people used to forward calls). So you put your phone down and then when you pick it up again to ring your bank you are actually still on the line the scammer. All they need to do is play a dial tone and pretend to answer the phone as the bank.
The best way to avoid this is to either use a different phone to make the call or wait longer than 5 minutes before calling. There is a timeout of around 5 minutes … I can’t remember exactly.
Does this make sense? I have always thought it is quite a neat trick.