Back then, a sign of Leftist street cred was a willingness to use forbidden words. Words like "Shit and "Fuck" were controversial then, and in some contexts could get you censored or jailed. But sometimes artists would use racist words because they push the envelope even further about what was forbidden and what wasn't. We lefties would find ourselves shocked when we heard the words, but we would remember the principle of free expression, and ambivalently accept them. The ambivalence was the point. We accepted that you had to be shocked into seeing the world in a new way.
Furthermore, most artists who use those words in a musical or literary context would never use them in conversation. I'm quite sure that neither Lennon nor Jagger ever referred to the numerous black artists they admired with the N-word. But when you create an imaginary character or are trying to make an artistic point in a song, the forbiddeness of the word creates a special artistic affect. I discuss this further here.
https://medium.com/@teedrockwell/yeah-about-yeah-about-that-scene-from-pulp-fiction-a9b6e46b5ff4
Lenny Bruce was the first person to claim that all obscene language, including racist words, needs to be used to rob it of its power. That idea is no longer fashionable. These days Leftist street cred comes from finding new words to ban, not breaking old bans. It was probably naive to think that we could overcome the power of racism by simply throwing off restrictions. But you have to understand that context see why very leftist people would occasionally use racist language in the 60s and 70s.
I discuss this further here.
https://teedrockwell.medium.com/the-fall-and-rise-of-forbidden-language-bb0a27152b09