Depending upon what your question means by why, either 1958 (in China), 1982 (Internationally) or some time in the 16th to mid-18th century (to Mandarin Chinese Speakers, depending on locale).
Officially, the Chinese government confirmed the spelling "Beijing" based on modern Hanyu Pinyin in 1958. It had previously been known as Peking, and had often had neither name but different ones such as Beiping. The spelling of Peking/Beijing (which represent the same word) was updated because the new, rationalised system of romanising Mandarin Chinese, Hanyu Pinyin, had just been completed, and the government didn't feel the need to keep archaic official spellings based on old european maps^1 . While initially Pinyin vs older romanisations was a political question, gradually use of Pinyin increased and by 1982 the International Organisation for Standardisation officially adopted Pinyin as the standard romanisation of Chinese, at which point Beijing's name is definitely Beijing.
But why does the dichotomy of Peking vs Beijing exist in the first place? Both names actually refer to the exact same word 北京, meaning "Northern Capital". Part of this is obscured by Hanyu Pinyin and Postal Map Romanisation's spelling conventions: what Pinyin spells 'b', Wade-Giles and PMR spell 'p' (the sound, for english speakers, is effectively intermediate in nature). If we spelled "Peking" like some fictional 15th century Pinyin would have, it would have been spelled "Beiging".
Thus, only one sound changed. But, as you ask, why did it? I'll try to keep the explanation below utilising as few bits of linguistics terminology as I can, to keep it accessible.
The Beijing-dialect Mandarin (but not all dialects of Mandarin) underwent a change after European contact and mapmaking where a series of shifts in pronunciation occured. Shifts in pronunciation are very common among all languages over time (it's how Old English became not the same as Modern English, for one, and how accents develop). So it's not necessarily surprising such a change occured in relatively recent history.
All of these changes happened before the vowel i only. Examples are pseudo-pinyin-ised to make only the sound change important:
Beiging -> Beijing, Dzinan -> Jinan
Tsingdao -> Qingdao, Chongking -> Chongqing
Guangsi -> Guangxi. Sin-hing > Xinxing.
Consequently, Mandarin no longer has any syllables pronounced 'king' 'ging' 'sin' 'hing' 'tsian' or other such syllables, as the consonants all changed in those positions. Most pronunciation changes in languages are regular (that is, universal within a given 'rule').
This pronunciation shift proceeds in two stages- the shift of gi/ki/hi to ji/chi/shi occurs first, some time in the 16th-17th century as it is already present in the fossilised pronunciations of Peking Opera. The second half, the shift of dzi/tsi/si to ji/chi/shi is first mentioned in the 團音正考 (Tuányīn Zhèngkǎo), a 1743 book whose title we could translate as something like: "A Correct Report on Palatal Sounds".
So we don't precisely know what year is the earliest year that residents of Beijing would have said their city's name was Beijing, but it was probably in the earliest stages of sustained contact with Europe. At the time, the standard however was Nanjing Dialect, which did not have this shift, so place names were written without it. Given the prominence of Beijing and the wide spread of the shift (almost all Mandarin dialects eventually adopt this pronunciation), by the early 19th century even European dictionaries of Chinese admit that Beijing-style pronunciations are dominant over their preferred Nanjing pronunciation.
This change might be relatively familiar, if you're familiar with Italian words, or even English. The same change of k/c -> ch and g -> j happened. Unlike in Mandarin (where Pinyin spells out the sound shift), languages like Italian keep the old consonants and just expect you to know the rule, as in words like Cappuccino and Luigi.
This sort of change, known as Palatalisation, is very common in the histories of many languages, including Japanese, all Slavic Languages, Mandarin Chinese, the Romance Languages, and Gaelic as ones you might be familiar with. Palatalisation is when certain vowels (typically /i/, but sometimes others too) tend to alter consonants in certain ways, especially turning t/ts/k into more ch-like noises (and d, dz or g into more j-like noises).
Sources:
1: Postal Map Romanisation is especially archaic, as by the time it was created in the mid-19th century palatalisation had already happened in Mandarin. Apparently it was based on a conservative Mandarin dialect where this had not happened, or was informed by the European preference for the names that had always been on their maps.
EDIT: Cleared up some mistakes in the text on years. Finalised.