This is WAD (Working As Designed) I believe, because otherwise it would make things too easy, AI can't reason who did it like human can even if undiscovered, AI does not assassinate otherwise than in retaliation and AI can't pause to kill Spymaster first and loads of others afterwards. Therefore it is better that AI always retaliates whether or not you are discovered. I presume it is easier to code too.
Remember that the big bads of assassination (badboy increase and prestige/piety reductions) don't happen when you are undiscovered, so it's worth it to not get caught.