Yes and no. The phrase was around before the 1940 cartoon, and became an idiom. It may have influenced the cartoon name.
In particular, the cartoon name is not related to the phrase “Tommy and Jerry” used during both World Wars (see below).
The first usage is an 1821 novel called Life in London, but with the full title of Life in London; or, The Day and Night Scenes of Jerry Hawthorn, Esq., and his elegant friend, Corinthian Tom, accompanied by Bob Logic, the Oxonian, in their Rambles and Sprees through the Metropolis. As the long title suggests, the novel told the story of Tom and Jerry and their adventures in Victorian London.
The book became a stage play entitled Tom and Jerry, or Life in London.
The phrase “Tom and Jerry” then became shorthand for young men prone to wild behavior. Bars were occasionally called “Tom and Jerry shops,” and there was a cocktail that also bore the name.
The Wikipedia page for the cartoon says:
“Tom and Jerry” was a commonplace phrase for youngsters indulging in riotous behaviour in 19th-century London
“Tom” is also a name for a male cat.
The characters weren’t named in the first cartoon. MGM then held an employee contest to name them. It’s assumed the winner produced the name from prior usage – the play, the novel, or the cocktail – but this has never been established.