As far as I can see, they are just synonyms used in the vernacular. The choice of word can simply be due to the established colloquial meaning.
The speaker may choose to use the word "attachment" when talking in a mechanical context and the word "accessory" when discussing phones or fashion.
In legal terms, you would use accessory (not attachment) when referring to an accomplice in a crime for instance. Context would dictate the appropriateness of these words (IMHO).
I'm sure a hardcore grammarian will chime in if there is a grammatical connection..... :)