How are towing companies legal? If you really think about it, isn’t it just theft and extortion?

They don’t steal your car, they remove it when it was illegally parked, or when you have not made the agreed-upon payments (and have also agreed to forfeiting the car in that case). You can get it back once paying the fees/fines.