It refers to cheating in gambling.
To "stack" a deck means to arrange the cards in a specific order.
If you can put the cards in a deck in the right order, then you will get all the good cards when the deck is dealt. The dishonest dealer would have to use magician's sleight-of-hand to bring the stacked deck into the game. He would have to give it a "false shuffle" (a maneuver that looks like a shuffle but doesn't really shuffle the cards).
Here are some other idioms that mean "cheating" or "swindling," that derive from gambling. I'm giving their literal meanings.
"Playing with loaded dice" means dice that are weighted to come up a certain way more often)
"Bottom dealing" means dealing a card off the bottom of the deck instead of the top.
A "rigged game" means a gambling or carnival game that has a mechanical feature that cheats the customer. For example, a roulette wheel can be "rigged" with an invisible pin that can pop out while the wheel is spinning and force the ball to fall into the "zero" slot.
"The shell game" is a con game in which the con artist hides a pea under one of three shells, moves the shells around quickly, and asks the "mark" (victim) to guess which shell the pea is under. "Three-card monte" is a variation of the same con game, with cards.