All three major averages closed out May with sizable gains Friday, with the S&P 500 and Nasdaq Composite seeing their best month since November 2023.