Any mob with the tag Team shouldn't attack you if you belong to their team, same with mob to mob.
A example with a pillager:
Put in the chat
/team add white_all
/team join white_all @s
/team join white_all @e[type=pillager]
And presto, the pillager shouldn't attack you because is your team, It doesn't matter if you hit him, he'll never attack you.
This work with zombie, skeleton, creeper... etc. And even special mobs like the vindicator "Jhonny" and The killer bunny.
But with a Piglin /Piglin Brute /Hoglin /Zoglin doesn't work, still attacking you.
Thank you for your report!
However, we are already tracking this issue, and this report is a Duplicate of MC-172304, which is a report that has not been resolved yet.
If you want, you can upvote the parent ticket, and enable watching to receive any updates about it - if you believe you have any information that may be important for this issue, please leave a comment on the parent. Please also use the search function in the future to prevent duplicate reports.
Quick Links:
📓 Issue Guidelines – 🛠 Community Support – 📧 Customer Support – ✍️ Feedback and Suggestions – 📖 Game Wiki
💬 Mojira Subreddit – 💬 Mojira Discord