The correct answer is: No error.
The sentence is grammatically correct. The word “when” is used to introduce a subordinate clause that describes the time when the police broke upon the robbers. The word “to” is used to introduce an infinitive phrase that describes the purpose of the robbers’ meeting in the lonely place.
The sentence could be rewritten as follows:
The police broke upon the robbers while they were in the lonely place to divide their booty.
However, the original sentence is also grammatically correct.