Like, how do we identify where we can consider zero work by the static
friction and where we cannot?
Static friction does work if the material at the point of application of the force is displaced.
Consider a block resting on a rough surface. A horizontal force less than the maximum possible static friction force between the block and surface is applied to the block. It doesn’t move. No work is done by the static friction force between the block and the supporting surface.
Now consider a block on top of another block. A net horizontal force is applied to the lower block. Both blocks accelerate as one as long as the maximum static friction force between the blocks is not exceeded.
The only horizontal force acting on the upper block responsible for its acceleration is the static friction force applied to it by the lower block. Since that static friction force displaces the material at the point of application of the upper block in the stationary frame supporting both blocks, the static friction force does positive work on the upper block in the stationary frame.
Now consider the total work done by static friction between the blocks. The equal and opposite static friction force the upper block applies to the lower block, per Newton's 3rd law, does negative work on the lower block since the force is in the opposite direction to the displacement of the lower block. Since the displacement of both blocks is the same, the net work done by static friction between the blocks is zero.
Hope this helps.