The reason it happened is the computer just took the loan and applied it as if it were a payment.
Technically, any loan cannot charge interest in advance. That's why they quickly 'fixed' it. In the real world, a bank could make a lot of money on a lot of loans that are paid in advance. In all cases, it is technically illegal, but if no one says anything, it continues.
I'd believe that banks don't specifically attempt to defraud a customer, but will default in favor of the bank before giving up a penny. But, will charge every cent it can unless a client discovers an error and reports it.