Elon Musk’s company beat analysts’ expectations in second quarter but shares dropped in after-hours trading