It was first done in a 1925 novel called The Heads of Cerberus.
The earliest clear example on film is The Brain That Wouldn’t Die (Also sometimes seen as The Head That Wouldn’t Die). This was produced in 1959 but not released until 1962, with an erroneous copyright notice that meant it was effectively in the public domain from day 1 - which is possibly why the idea of a living brain kept alive in a jar has become so oft-repeated.