The social media company’s earnings and advertising revenue both topped estimates amid a leadership shuffle.