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.