I have also noticed that NPC attack counts when guarding a planet.
I'm also having a related issue now. I guarded a planet when I had the -50% defence debuff from the xrp warp station, I then used a containment cage to remove the debuff and guarded another planet then went back to guarding the 1 i wanted to, but my defence was still half eve though it showed as normal on my ship tab.
My defence:

My Defence when guarding a planet:
