Droooze's answer is a good one. I'd like to add onto that here.
Origins of the "metal can" meaning for 缶
Even before, and especially after, the fall of the Edo 幕府【ばくふ】 (shogunate) in 1868, Japanese researchers were busy trying to find out what Japan had missed out on during the long period of 鎖国【さこく】 ("locked country") policy, when the Tokugawa regime strictly controlled foreign access to and contact with Japan. During this time, many new words and concepts were imported into Japanese, with old words sometimes pressed into service with new meanings. Some common terms that we don't even think about, like 社会【しゃかい】 ("society") and 自由【じゆう】 ("freedom") were re-forgings of older words to apply to new meanings.
From what I can find, it appears that 缶【かん】 is one such similar term. According to Shogakukan's 国語大辞典【こくごだいじてん】 (KDJ) entry here, the word 缶【かん】 in reference to a "can" dates from the late 1800s. Both the KDJ entry and the separate Daijisen entry here agree that this particular sense came from either English can or Dutch kan, with the kanji spelling an example of ateji usage.
As droooze notes, this kanji 缶 had a long history in Japanese and Chinese prior to the late 1800s, referring more generally to a container of some sort -- possibly an earthenware, glass, or ceramic "jar", or a metal "pot" or "water bucket", that kind of thing. The shift in sense from "metal pot or water bucket" to "metal can" isn't very far, and indicates the kind of creative linguistic rejiggering that happened a lot in the late 1800s in Japan.
Why use kanji for a borrowed term
There are a many borrowed words that have kanji forms. The most obvious ones are almost all of the on'yomi terms out there -- these mostly came into the Japanese language as borrowings from Middle Chinese.
That said, your question is clearly asking about more recent borrowings. Even then, there are a few such terms that have common kanji forms. The more familiar ones were borrowed earlier on in the course of Japanese contact with Europeans, such as 天麩羅【てんぷら】 (from an apparent conflation of Portuguese temperar and tempora), or 煙草【たばこ】 (from Spanish and Portuguese tabaco, in turn from terms in either Taíno and/or Arabic), or 如雨露【じょうろ】 (from Portuguese jarro), or 襦袢【じゅばん】 (from Portuguese gibão). So using kanji for borrowings isn't unheard of.
缶 is a much more recent borrowing, comparatively, but it's also on the edge of old enough that the spelling has had time for wide adoption. Combine that with the way the reading conveniently overlaps with the borrowed foreign word, the simplicity of the character (not too many strokes), and that it is perhaps visually evocative of a can, and we see persistent use in modern writing.