Also a bit of avoiding fraud from driver's side - if the driver is allowed to take money out, it's impossible to control whether all the payments actually got to the end point.
That said, I've seen systems where the drivers give change - e.g. in Israel - and that's wasn't a big deal. So I guess it also depends on the locality.
Driver presses the button for a special ticket, customer inserts coins or bills, the machine automatically gives exact change. Alternatively, pay with NFC, card, etc.
Honestly some of the things mentioned in here are mind bending. I have public transport experience from both London and a small country on the eastern side of Europe, and both were efficient, fast and safe. What the fuck is wrong with the US when people are scared to take public transport because they can get robbed?