Tenants under contract typically go with the property. If the eviction ban is an issue, then it merely transfers that issue to a new owner, who has to decide whether or not to take on the risk.
So "You could always sell" isn't really feasible in all situations.