not actually sure but it's been a part of our language for 100s of years. interestingly, in america a 'fanny' is a bum, which suggests that it stemmed from s.western dialect sometime before the mayflower sailed, but which version is the original i don't know.
it may be the Americans have just bowdlerised it by moving it backwards... anyway, the dictionaries don't know but suggest it might be connected to the novel Fanny Hill in the 1700s.
The earliest recorded use of the word in this sense in Britain was in 1879, so it has not been around for that long. The earliest known use of the word in its American sense comes from some fifty years later. Like all such name-words - eg willy or the diminutive form of Richard for penis - there is no known source, as they first appeared as nursery-versions of the medical terms.