Costco topped quarterly earnings and revenue expectations, even as sales trends at the membership club slowed.