I'm not sure when it was decided that "nigger" was to be an offensive word.
It certainly was NOT offensive in the 19th century, and I have met many older people who grew up in the 1920s or 1930s who routinely used it without any ill intention. However, I have seen some written sources from around that time insisting that "negro" was more polite - though as to why I couldn't say and they didn't say. It might have been more linguistic or cultural snobbery than anything else.
But I think it was pretty well relegated to "hateful" status by the 1960s - at least by some parts of society, but not necessarily the parts that actually used it.
As to why, I think the conversion of a commonly used term into "hate speech" was really intended as an attack on traditional white American culture, and as a way to sow division between black people and the sort of traditional white folk who used the term habitually.
A few years ago you might recall that the almost universally used "OK" hand gesture was jokingly deemed hate speech, and a surprisingly large number of people started taking it seriously, and people even lost jobs and opportunities over it. Never underestimate the insanity of the political class.
Of course the "OK" hand gesture is so universal and habitual that it can't really gain serious traction with the general public - but look how far it did get in a very short time despite that obvious handicap!
However, a change in how we perceive language, especially when use of a term differs somewhat between different cultures or classes, is relatively easy to accomplish.
So, if someone wants to create disunity between southern whites and southern blacks, who historically were pretty united even during the war between the states and reconstruction, just tell the southern blacks that the word that the southern whites habitually use to describe them is a racial slur and an indication of hatred - keep repeating it in newspapers, on radio, on television, in schools, and everywhere ... over time it will color their perception of history, and they will read old texts and become angry every time an old southern writer mentioned their people, certain that it was intended as a slur when it obviously was not. It's a way to change historic texts without having to edit a one of them - simply change the meaning of the word instead. Voila! hatred and division, and as a bonus you can claim to be the morally superior people who brought this ancient hatred to their attention and helped them see how they were always exploited by the people they had formerly seen as their friends!
So, I'm beginning to doubt that it was either accidental or good-intentioned.