There are 22 variant spellings of piccaninny in the compact OED. It seems to be a West Indian (Caribbean) derivation from Spanish (pequeno) or Portuguese (pequenino). It was originally used as just a term for a small child, and first found in English in 1657 and 1681 in that sense, and later and much later. But the term could also just mean 'little'.
OED doesn't note T. D'Urfey's song in "Don Quixote', 1696, commencing:
Dear Pickinniny, if half a Guinny,
To Love will not win ye,
I lay it here down;
We must be Thrifty,
'Twill serve to shift ye,
And I know Fifty,
Will do't for a Crown.
D'Urfey used it to mean a whore, but nothing in his song ('Pills' I, p. 283, 1719) implies she was black.
Just when blacks took it to be derogatory I can't say, but my guess would be sometime before slavery was abolished in the USA. It seems to be taken only as derogatory now.