This may happen if you are using Stripe as your payment gateway. What happens is, when the payment failed, it was marked as past due in Stripe. And even though the subscription was later canceled or expired, there is still an outstanding balance for the customer.
When the customer later entered updated payment information while purchasing a new membership, Stripe detected the new payment details and collected the overdue balance.
The best solution is to refund the customer the charge for the old subscription. You may also wish to contact Stripe support and see if there is any way to prevent this scenario in the future.