A sale does not end the lease. The buyer steps into the landlord's place with the same rights under it, so the tenant does not have to move just because the house sells. See Maryland Real Property § 8-101.
Maryland's tenant-opportunity law generally applies to a 1-to-3-unit rental when a tenant named on the written lease has lived there at least six months. Before you offer the property to anyone else, send written notice of the tenant's right to make an offer. The tenant has 30 days to make an offer; if it matches the terms in your notice, you must accept. An unsolicited third-party offer, or an offer at least 10% below the lowest price previously offered to the tenant, can also give the tenant 30 days to match. Some family, court-ordered, foreclosure, estate, and trust transfers are exempt. See Maryland Real Property § 8-119.