“If [X] gets outlawed, only outlaws will [X′]” is what you might call a snowclone:
A snowclone is a type of cliché and phrasal template originally defined as "a multi-use, customizable, instantly recognizable, time-worn, quoted or misquoted phrase or sentence that can be used in an entirely open array of different variants"
Classic examples of snowclones are “[X] is the new [Y]” (like “gray is the new black”) and “If Eskimos have [N] words for snow, [X] surely have [Y] words for [Z]”.
I searched using the Google Books Ngram Viewer for “outlawed only outlaws” and found this saying had no examples until the late 1960s. The examples shown from that period are invariably the version of the phrase with guns. Further expanding the search in Google Books search to “outlawed * only outlaws” I antedated the saying to a science fiction publication in 1955:
Outlawing it would be as futile as outlawing ambition; if it is outlawed, then only outlaws would have its advantages, and lawful people would be helpless.
— Astouding science-fiction: Volume 56, Issue 1, 1955
It is not clear from the snippet what the context of “it” is, but this is clearly an example of this phrasal template. An even earlier citation, from 1930, anticipates the phrasal template with respect to firearms, but doesn’t quite match it:
No one has a constitutional right to carry a concealed pistol or other such weapon. The right to bear arms has nothing to do with pistol carrying when the pistol is outlawed. Only outlaws will carry it. It became interwoven with our ...
— Hearings, 1930
We can guess from this that the original use of the phrase relates to guns. The first examples in the Google Books corpus which match the template are from 1968, and clearly reference guns:
If guns are outlawed, only outlaws will have guns.
— From a publication by Christian Nationalist Crusade, 1968.
By 1969, this trope is regarded as a well-known standard argument about gun-control legislation:
Several forms of this argument state that gun-control legislation simply is not an effective way of reducing crime and violence: (i) Guns don't kill people, people kill people; (ii) when guns are outlawed, only outlaws will have guns ...
— Science, Volume 164
Since the late 1960s, the phrase has enjoyed some usage, as shown by this Ngram graph: