Less than two months ago, shares of Tesla Inc. were on their way to just the third losing year in the electric-vehicle maker’s decade-and-a-half as a public company. But after a furious rally in the last seven weeks, the stock is suddenly among the S&P 500 Index’s best performers for 2024.