The quick summary of my lengthy post is this: People have been doing it for as long as they have been able to get away with it.
The answer is that this practice began at the very beginning of the invention of motion pictures with sound, in 1923.
However the Wikipedia article on sound film claims that there were public screenings of films as early as 1914 where a silent film was accompanied by live actors speaking over amplified playback of music from a phonograph.
In virtually every motion picture you have ever seen, if there is a musical performance, the performers are miming playing the instruments and are lip-synching the vocals. This is because of practical and budgetary considerations; it would be prohibitively expensive and time-consuming for a film production crew to film a group of musicians performing live on a soundstage. It is much easier and it results in much higher sound quality simply to use a pre-recorded performance.
As far as television, the practice of lip-synching goes back to the widespread popularity of television broadcasts, starting in the 1950s.
As far as live performance, the practice goes back as far as the availability of public address systems and amplification which were adequate to play a recording and make it sound as good in audio quality as what could be achieved with live performance.
I would surmise that the earliest example of a stage performer playing live in concert with a tape-recorded backup was very likely that of guitarist Les Paul circa 1949, shortly after he obtained one of the first mass-produced tape recording machines available in the Western Hemisphere. He certainly used this technique in his duets with singer Mary Ford, from 1948 through the 1950s.
Starting in this same time period, there began a long-established practice in avant-garde classical music called music for tape whereby a composer would construct an elaborate studio recording involving manipulations and transformations of found sounds and electronic elements. In some cases, these compositions were written to be performed by a live acoustic musician on stage, backed by a taped recording. You can find many examples of such compositions with titles like "Sonata for Tape and Piano", "Music for Tape and Flute" and the like.
Lip-synching and miming playing musical instruments on television was made standard practice by the weekly television program American Bandstand in the USA. American Bandstand broadcast from 1952 through 1989. All the bands and artists (many quite famous) that appeared on this show were required to mime and lip-synch performances of their recorded hit records. There were a host of similar television shows in many nations of the world, most notably a show in England called Top of the Pops from 1964 through 2006 -- although it is possible that some of those shows might have permitted some bands to actually perform live from time to time.
The rock bands Pink Floyd and The Who were performing live in concert with the use of some tape-recorded backing tracks on certain songs going back to the late 1960s. They tended to use the tape recordings for parts of arrangements that were elaborately constructed in the recording studio and would have been difficult or impossible to perform live. However, they would not mime or lip-synch to these parts; it was obvious to the audience that certain parts of the arrangement were provided by a tape machine playing back while the other parts were being performed live by the musicians.
Since that time, many musical groups in all styles of music, from classical acoustic chamber groups (the Kronos Quartet for example) to electronic synth-pop have performed along with pre-recorded tracks, either on tape or another recording device, or using electronic music sequencers and MIDI triggering synthesizers, samplers and electronic instruments. It would seem that virtually every band centered around synthesizers has made heavy use of pre-recorded and sequenced backing tracks in live performance, from the first availability of synthesizers that could be used on stage, and that goes back to about 1968. With such bands, it has always been difficult for the audience to figure out what parts are being played by live musicians and what parts are pre-recorded or sequenced.
It is likely that many well-known performing singers surreptitiously used pre-recorded vocals and lip-synched on stage for a long time before it became widely known to the public. The first well-known controversy about this involved the rock band the Electric Light Orchestra, in the late 1970s and early 1980s.
The most famous case of performers lip-synching on stage (and not acknowledging it to the audience) is of course that of the notorious Milli Vanilli in 1989. This previously multi-million-selling, international superstar act became reviled by the public and the controversy destroyed their careers.