In mid-2017, the giant landlord Brookfield Property Partners L.P. was in advanced talks to buy the Lord & Taylor department store building in New York City for about $700 million, when an unexpected buyer swooped in and sealed a deal, according to people familiar with the matter.

Behind the deal was WeWork Cos., which put together the $850 million purchase, a hefty premium and a surprising move for a firm that leases buildings and subleases the office space to other companies.

WeWork...