An unexpected ending to a sentence or statement that leads the reader or listener to reinterpret the first part of the statement is called a paraprosdokian.
It is a figure of speech often used for comic or dramatic effect, as in “I haven’t slept for ten days, because that would be too long.”