A run-in with the law, a few beers, and a wild idea in a Texas jail led to one of country music’s biggest hits.