Costco reported fiscal second-quarter sales that topped analysts’ estimates, but earnings missed as costs rose.