It means that it is unwise to commit a crime because, however tempting it might seem, crime does not pay. For example, a bank robber will probably be caught and not get to keep the stolen money.
It was a kind of slogan in the movie industry in the days of the Motion Picture Production Code in the United States. During the years 1930-1968, the movie industry voluntarily censored itself. During those days, for example, a bedroom--even a married couple's bedroom--never showed a double bed; it always showed separated twin beds. And shots of bathrooms never showed a toilet.
Part of the code was that, in the movies, "crime does not pay." If gangsters were shown, they could not be made to seem too successful or glamorous, and, in the end, they would always be caught and brought to justice.