Jim Cramer learned a lesson from the market's reaction to President Donald Trump's action on immigration.

Usually when a president has a pro-business agenda, the market will gobble it up and buy stocks. But when things are happening too fast with issues that have nothing to do with business, investors get nervous and the stock market begins to sell off.

"Politics and money do mix, they just don't mix all that easily when it comes to the stock market," the "Mad Money" host said.

This led Cramer to spot a new pattern in the stock market on Monday.

As soon as the media turned negative about Trump's actions, shares of typical "Trump stocks" sold off in the S&P 500 futures. Then when the stocks of the high-quality companies started to bottom, big institutions started to step in and use the politics-inspired negativity to buy.

Jin Lee | Bloomberg | Getty Images

Traders on the floor of the New York Stock Exchange

The opportunists recognize that the economy will not be derailed by visas, green cards, refugees or immigration, Cramer said.

"The stock market is simply weighing controversial political news versus equity valuations and it likes those valuations when the smoke clears," Cramer said.

The market didn't crash just because Trump did something that generated public blowback, Cramer said. It doesn't mean the market will erase all of its gains since the election. If he did it every day, then the market would head lower.

As for the CEOs who have spoken out against Trump, Cramer said this wasn't an easy call for him because he can't remember seeing this kind of outcry from executives before. Many executives have publicly advocated against regulation before and it has had no impact on their stocks.

The critical nature of CEOs on Trump is likely not going to have an impact on the fundamentals of the company. Investors buy a stock of a company because they like its business prospects, not because of the CEO's politics.

However, what does worry Cramer is whether Trump will target the company and potentially damage its business.

"Trump never backs down from a fight, so he might feel the need to retaliate, and that has got to be a factor going forward when you are thinking about buying these stocks," Cramer said.