If anyone looked out of their window now, even beady-eyed Mrs. Dursley, they wouldn’t be able to see anything that was happening down on the pavement. Dumbledore slipped the Put-Outer back inside his cloak and set off down the street toward number four, where he sat down on the wall next to the cat. He didn’t look at it, but after a moment he spoke to it.
“Fancy seeing you here, Professor McGonagall.”
He turned to smile at the tabby, but it had gone. Instead he was smiling at a rather severe-looking woman who was wearing square glasses exactly the shape of the markings the cat had had around its eyes. She, too, was wearing a cloak, an emerald one. Her black hair was drawn into a tight bun. She looked distinctly ruffled. (Harry Potter and the Sorcerer's Stone)
As commented by @Walter, in OP's context, fancy is a synonym of imagine, believe. But the usage is becoming increasingly "dated"...
Many of the above instances will be the idiomatic exclamation "Well, fancy that"! (equivalent to "Imagine that!", "What a surprise!", "How strange!", etc.). In OP's context, Dumbledore could quite naturally have used any of those (possibly preceded or followed by something like "I didn't expect to see you here!").
Note that Dumbledore is an elderly British schoolmaster in a relatively "formal" situation (he's greeting Professor McGonagall, one of his staff who apparently happens to have adopted the form of a cat).
Idiomatic expressions as used by Dumbledore won't necessarily be so natural for younger speakers, and per @StoneyB's comment below, even Dumbledore is speaking ironically here. Brits in particular still use fancy = like, want, be attracted to quite naturally today, but fancy = imagine, believe, think is now largely confined to ironic/sarcastic contexts.