The original meaning is "bad, rotten" in relation to wood. From there it was applied to people as a derogatory term.
It was then presumably intentionally claimed as a badge of pride for the punk music scene, where it effectively means "anti-orthodox, anti-authority, rebellious, outsider"
It gets used in pretty diverse circumstances, many of which don't share much meaning with the original music scene meaning. Like steampunk is basically a purely aesthetic term, with none of the political connotations.