According to Art. 261 I CO, where, after concluding the contract, the landlord alienates the object or is dispossessed of it in debt collection or bankruptcy proceedings, the lease passes to the acquire together with ownership of the object.
However, the new owner may terminate the lease as of the next legally admissible termination date, if he claims an urgent need of such premises for himself, his close relatives or in-laws (Art. 261 II lit. a CO).
Such early termination of the lease agreement may be challenged in Court when the termination is given in a manner contrary to good faith (basically, if the urgent need claimed by the new owner is not real but just a pretext to end the contract).
The tenant may also seek an extension of the lease in Court. However, in practice and if the urgency claimed by the new owner is real, the extension will be granted only for a short period of time.