In Texas, when a rental is sold, the new owner generally has to honor the tenant's lease. A sale does not cancel it. The tenant does not have to move out unless a court orders an eviction.
Say a tenant has a year-long lease and you sell after six months. Unless the lease says something different, the new owner steps in and honors the remaining six months. When the lease ends, the new owner can decide whether to renew and on what terms.
Read your lease for any clause about a sale. Then tell any buyer about the lease up front. A buyer who plans to live in the house or wants it empty may price that in, or may not be the right buyer.
This is why many investors, including us, can buy a rental with the tenant staying. We may buy the property ourselves or work with a partner buyer. You see the terms in writing before you sign.