It means exchanging sth slinkingly.
狸猫换太子 is a famous legend story supposed happened in Song dynasty.
Here's an explanation of the story on wikipedia.
Wild Cat Exchanged for Crown Prince (狸貓換太子): Bao Zheng met a woman
claiming to be the mother of the current Emperor Renzong. Dozens of
years ago, she had been Consort Li, an imperial concubine of Emperor
Zhenzong's, before falling out of favour for supposedly giving birth
to a bloody dead wild cat. What really happened was a jealous Consort
Liu plotting with eunuch Guo Huai (郭槐) to secretly swap Li's infant
with a skinned wild cat minutes after birth and order palace maid Kou
Zhu (寇珠) to kill the baby. But Kou gave the baby to chief eunuch Chen
Lin (陳琳) who secretly brought the child to the Eighth Prince, a
younger brother of Emperor Zhenzong. Kou was later tortured to death
by Guo when Consort Liu began to suspect about the fate of the baby
child. The child was raised by the Eighth Prince as his own son and
was subsequently selected to ascend to the throne as Emperor Renzong
after Emperor Zhenzong died without an heir. Due to the passage of
time, getting evidence presented a challenge. With the help of a woman
dressed as Kou's ghost, Bao dressed himself as the hell overlord Yama
and used Guo's fear of the supernatural and guilt to extract his
confession. When the verdict was out, the emperor was reluctant to
accept Consort Li. Bao then admonished the emperor and ordered a set
of beatings for him for lack of filial piety. The emperor's Dragon
Robe was beaten instead. Emperor Renzong eventually accepted his
mother and elevated her as the new empress dowager.