One possible origin comes
from the whistle sound of a sword as it swishes through the air when
decapitating someone. The thought is that the expression would be uttered if
the decapitation was a clean cut. Although, I don’t really associate the word
clean with a decapitation.
A second possible origin comes from a whistle made from a reed or a piece of wood. Small debris
or moisture can adversely affect a whistle if it is not properly cleaned. In
order for a whistle, or a similar instrument, to make proper sounds or tones it
must be kept clean. Another possible origin comes from trains. Trains have, or had, brass whistles for signalling and warning people. These whistles were always kept clean and shiny, hence the phrase clean as a whistle.
This phrase has a number of different possible origins but just be thankful that we don’t use it for decapitations anymore.
I thank Danielle for suggesting this phrase.