Recession fears have risen lately amid weaker economic data and increasing trade tensions. Monthly jobs growth fell to just 75,000 in May — missing an estimate of 180,000 — while manufacturing activity grew last month at its slowest pace since October 2016. Meanwhile, China and the U.S. continue to strengthen their rhetoric against each other on the trade front.

Bank of America analyst Joanna Gajuk noted that pre-need service companies, which make funeral arrangements before the person dies, only saw a "slight pullback" in business during the last recession as "75% of the pre-need funeral customers pay in one lump sum." She added that 40% to 50% of cemetery plot and memorial space purchases are also paid in a lump sum.

Investors worried about a potential recession can seek shelter in a morbid sector of the market: death companies.

However, "death care is recession resistant," Gajuk said.

The analyst also noted the industry is likely to consolidate as smaller companies struggle to shift to rising demand for cremation services. This consolidation will continue for the next decade, Gajuk said.

One company that can benefit from these trends is Service Corp. International, a funeral goods and services provider, given its scale and "the favorable aging demographic tailwinds," Gajuk said. She added that growing dividends, "solid" free cash flow and "manageable" leverage make the stock a buy.

The stock has also outperformed the S&P 500 in two of the past three recessions. It rose 28.5% in the early 1990s recession and 70.1% in the early 2000s recession. The S&P 500 rose 4.4% in the former and dropped 8.2% in the latter.

Service Corp. lagged the S&P 500 in the Great Recession, however. The stock fell 57.9% in that time while the S&P 500 lost 37.6%.

Subscribe to CNBC on YouTube.