When you attack an entity in survival then switch to spectator mode the entities will still track the player. One would expect them to 'untrack' you just as it does when you switch from survival to creative.
Steps to reproduce:
1) Attack an entity in survival
2) Change game mode to Spectator
Duplicate of MC-46596 - If you have not, please use the search function in the future, to see if your bug has already been submitted. If you could not find the original report, please comment with the keywords you searched for.