Today's idiom was uttered during fights, I'm thinking when an especially powerful hit provided the needed knockout in a fight. But it became a popular phrase in the mid-1960s when Pepsi-Cola wanted to increase the popularity of a southern drink called Mountain Dew. It was a regional drink that Pepsi thought had potential to become popular nationwide. The first ad campaign promised to "knock the socks off" anyone who drank it. (source)
The phrase today is a positive one meaning that someone who has their socks knocked off has been surprised or astonished.