Retained earnings represent undistributed earnings.
Since these earnings belong to shareholders, who could invest them in similar risk investments, it stands to reason that if a firm chooses not to distribute them as dividends, it should earn a rate of return on these earnings that is commensurate with what shareholders can earn in the market.
Hence retained earnings have an opportunity cost for shareholders.