My best understanding is that Tesla doesn't take more money selling credits than selling cars, in terms of revenue. Cars is a bigger revenue source. But cars have less profit, cuz you have to build a whole car.
So they can sell a car close to cost. Then sell a carbon credit at basically zero additional cost and make pure profit, and that's where the operating profit comes from. Past that, I'm still vague on how the program is run.