This is an idiom that refers to situations involving secrecy and intrigue.
In ancient times, assassins or thieves would wear cloaks which hid their weapons, often a dagger. This enabled the classic scenario of someone pulling a knife from beneath their robes and killing someone, which I suppose evokes intrigue.
In A Knight’s Tale, written in the late 1300s, Chaucer wrote about…
The smyler with the knyf under the cloke.
Old English spelling aside, Chaucer was speaking of someone who smiles at you, then produces a hidden weapon to harm you. So, again with the intrigue.
In 17th Century Spain, swashbuckling plays were called comedias de capa y espada, which translates to “cloak-and-dagger plays.”