Returned lease now selling for much cheaper (31%)

I returned my lease 2 months ago.
It was a 2 year lease, BMW 535i Xdrive, loaner car
The residual value was $44572. I returned it to a different dealer, wasn’t a problem, they were quite cool about it, didn’t seem to care. The car had 2 accidents already, with pretty big bills ($11900+$21500).
I was sure they would just send the car to auction, being the bank’s problem now.
Instead, it now popped up on their website, selling for $30495 (31% less than the RV)

The car was great for me, was repaired very well, but I still would have not bought it for $30495 since it would be hard for me to sell it at some point given its history

Any thoughts about the inner workings of this business?
Did the dealer prefer to keep it at a big discount from the bank?
Did the bank pressure the dealer into taking this “hot potato” off their hands?
Did the bank really lose money on this deal?
Would a customer that knows their car has depreciated because of an accident make a proposal at the time of return and say, “look, I am willing to keep this car, but for less”?

BMW financial probably discounted the car aggressively and the dealer bought it.

I think in the past people could go to the bmw dealer and ask the dealer to buyout the car at a discount from bmw financial then turn around and resell it to the same person for a small profit. But recently bmw has cracked down on that and it is no long allowed.