#khuzdul
These are two different questions, but since my answer for both comes from the same passage in the appendices, I’m answering them together. About Khuzdul, and the use of it by the dwarves, Tolkien says:
Yet in secret (a secret which unlike the Elves, they did not willingly unlock, even to their friends) they used their own strange tongue, changed little by the years; for it had become a tongue of lore rather than a cradle-speech, and they tended it and guarded it as a treasure of the past. Few of other races have succeeded in learning it. In this history it appears only in such place-names as Gimli revealed to his companions; and in the battle-cry which he uttered in the siege of the Hornburg. That at least was not secret, and had been heard on many a field since the world was young. Baruk Khazad! Khazad-aimenu! ’Axes of the Dwarves! The Dwarves are upon you!’
The two bolded parts are the important bits in answering your questions. As for when dwarves learned Khuzdul, I’ve got to say right off the bat that I don’t think there is an “official” answer to this - Tolkien wrote so little about Khuzdul (and, honestly, the dwarves in general), that I really don’t know for sure when they learned Khuzdul. I’m tempted to say that they would have learned it from birth (it being such an important part of their culture,) but this passage makes me question that impulse. Tolkien says that Khuzdul was “a tongue of lore rather than a cradle-speech”, which implies to me that it wasn’t used as much as a day-to-day language, but rather was saved for important events. In the end, I think the debate could go either way, so I’d say believe whichever version you like more. :)
As for Aragorn learning Khuzdul - I like this thought, and if this scene occurred in the book, I’d say that you were probably right. But, since this whole exchange happens only in the movie version, and Tolkien was very clear about Khuzdul being a language that the dwarves worked to keep secret from other races, I think it’s actually not very likely, unfortunately. He says right here that dwarves didn’t teach Khuzdul to other people, “even to their friends.” And I haven’t read anything to suggest that Aragorn had dwarvish friends before Gimli, so I don’t think it likely.
Now, I wouldn’t be all that surprised if Elrond could speak Khuzdul (the dwarves weren’t quite so secretive about their language in the First Age, and there are mentions of some Noldorin elves learning the language to study it. Elrond being such a loremaster, it’s possible he studied the language as well.) Assuming that he does speak Khuzdul, I suppose it is possible that he might have taught Aragorn a little bit of it (though Tolkien also mentions that the men of the First Age that the dwarves originally tried to teach Khuzdul too had a lot of difficulty picking up the language, so I wouldn’t think that Aragorn was too proficient.) So it’s possible - though improbable - that Aragorn would understand Gimli’s insult because of that. More likely, though, I think he could just tell that it was an insult based on Gimli’s tone of voice.
SOURCES: LOTR, LOTR Appendix F, History of Middle Earth vol. 12 (“Of Dwarves and Men”), The Silmarillion
Elrond learning Khuzdul in the First Age doesn’t really make much sense, unless you’re thinking Maglorspoke it? It’s true that Dwarves got along better with Elves in the First Age, and that a few Elves learned Khuzdul then (Curufin certainly, probably Celebrimbor, probably Eöl) but that was before the Sindar retaliated for Thingol’s death by killing every Dwarf within Doriath’s borders, and the Dwarves retaliated for that by sacking Menegroth, and Beren retaliated for that by ambushing and killing all the Dwarves of Nogrod, and all of that was before Elrond was born. I can’t imagine Khuzdul spoken at Sirion: all Dwarves were hated by the Sindar by that point, and anyone who knew it probably kept quiet about that.
In the Second Age one assumes that the most trusted of the Noldor of Ost-in-Edhil learned it, but Elrond never lived there, and very very few of them survived its fall. I don’t imagine Elrond as ever prejudiced against Dwarves, but it seems like they mostly taught their language to those with whom they had a close working relationship, and he doesn’t seem to have ever been positioned (geographically or in terms of skills) to have that. If anything I can imagine them being less inclined to teach it to someone whose interest is entirely academic/historical rather than creative/personal.