Realty Income said it would buy Spirit Realty Capital in an all-stock deal valued at $9.3 billion as it looks to expand its real estate portfolio.