[System-agnostic] Running intelligent and informed adversaries that feel fair - eviltoast

So, I like stories where everyone is competent, and as a GM I try to run my villains as playing to win. My goal is for the players to have a good time, but the enemies will use every resource at their disposal to achieve their aims: they will retreat if continuing to give battle is a bad idea, they will go scorched earth if it’s in their interest, they will defeat the players in detail or simply attack with unfair, overwhelming numbers.

Sometimes this results in a beautiful, game-defining moment where the players work out what their powerful and intelligent adversary is doing, and then proceed to outwit them. More often, though, the players win the way players do: shenanigans and brute force until the day is won. This can also be fun, and obviously not every story arc needs to end with an I-know-you-know-I-know battle of wits.

The problem here is that when this happens my players usually don’t ever figure out what the plan was – and what from my side of the screen was a clever ruse or subtle stratagem, to the players looks more like an ass-pull. My players don’t know that they set off a silent alarm and the security forces stalked them around the building before ambushing them from three directions, they just got a random encounter where they were surrounded by guards. They don’t know that the shopkeeper they revealed their true identities to reported them to the BBEG for a bounty, they just know that the army knew they were coming even though they were trying to be stealthy.

So, GMs with similar philosophies: How do you make it feel satisfying / fair when the players are fighting an intelligent and coordinated adversary who knows more than they do?