When they went upstairs to the crowded common room, it was to
find Fred and George had set off half a dozen Dungbombs in a fit of
end-of-term high spirits.
— Harry Potter and the Prisoner of Azkaban by J.K. Rowling
It was to find~ doesn’t seem like a regular cleft structure. What kind of one is it?
It’s known as the past conditional, “it was to” follows from “When” in this sentence, it can sometimes follow “if”. Having said that, it is an unusual way of saying the sentence however not incorrect. The normal way would probably be “they found”.
Source : Link , Question Author : Listenever , Answer Author : Sean O’Donoghue