'Rack' comes from the word 'wrack', which is no longer used. It was transformed into 'wreck', which we use today.
In older English, 'going to wrack (wreck)' was a common expression meaning to turn bad or ruin oneself. The 'w' was dropped and 'ruin' was added, simply because 'rack and ruin' gave it more emphasis.
In 'rack and ruin', there is no rack involved, as in a torture device that stretches someone.
However, there IS a torture device in 'on the rack' - it is used when somebody is being harshly questioned or criticized.
"The boss had Charlie on the rack for an hour about his mistake."