It's "literally all" of the profit because Tesla controls the timing and amount of credits sold each quarter, and adjusted the sales of credits so that it could make the "4 consecutive quarters" profitability threshold for making the S&P500 rather than selling them all in one quarter as they did in the past.
Profits are not fungible. Companies can, and do, determine profit and loss separately for each line of business, because it matters both for financial reporting purposes and for tax purposes. Even Tesla acknowledges that it is not profitably making and selling cars under GAAP (i.e., under industry-standard accounting); their unit margin deliberately excludes items that would normally be ratably allocated to each unit. Hell, Tesla even fired most of its marketing department and cut its marketing budget so that it could goose the financial metrics it needed to make the S&P.
In that sense, it worked. Tesla is on the S&P. The downside to being on the S&P though is greater scrutiny and more price friction. Tesla can no longer count on retail investors to goose stock prices with marketing stunts.