Major U.S. stock indexes set records again Thursday, the first time since Dec. 31, 1999, that the Dow Jones Industrial Average, the S&P 500 and the Nasdaq Composite have hit those milestones on the same day.

The rally was sparked by higher oil prices and earnings reports from U.S. retailers that weren’t as weak as feared.

Consumer-discretionary...