Chabad of Midtown Manhattan has closed on its purchase of a building on 509 Fifth Ave. for just under $40 million.