Used to mean you knew something was going to happen without prior explicit knowledge.
Usually used with emphasis on "how" and sounds like a statement, rather than a question.
your friend is calling you on the phone: "how did i know" - implies you knew they were going to call you, whether you really did or not.