There is a machine that plugs in to the lock to 'read' the history. On some systems you'll find what looks like a little audio plug on the bottom of the lock, others the cover has to be taken off.
And yes, hotels will occasionally lock a guest out of a room, whether mechanical or electronic locks, if there is a concern about payment methods. This happens more often on long stay visits where a substantial balance is building up on the account. Sometimes if the card expires or goes over limit during the stay. Usually they don't do that unless they've had problems contacting the guest, but YMMV.