The answer is ところを, not ところに, as I would have expected.
The textbook also includes the examples 寝ているところを写真に撮られてしまった。and 木村さんが出かけるところを見ました。
I’ve been under the impression that ところを is used after a state someone else is in when thanking them or asking them for something, but these examples are going against that. Would ところに be incorrect the latter two examples? Why is it wrong in the former sentence?
This is a tricky one. I used to hate this type of question, and still do for the large part .
The answer is mainly because of. 親切な人に. You are intentionally going out of your way to get someone to do something for you, so therefore you can think of it as you are ‘using’ を, the situation of being lost in order to find help. Key word being ‘intentionally’.
ところに implies more of a coincidental occurence, such as the following -
道に迷って困っていたところに、親切な人が通りかかって助けてもらいました。
In this sentence you still get the person to help you, but the focus is more that the person happened to stumble upon you (in the situation) of being lost. Rather than you specifically going out of your way to find them.
Basically - Is the situation being utilized for an express purpose? If yes then を. Is the time of the occurence more the focus where something happened within it? If yes then に.
I have one more question. Why does the example sentence used in the book 寝ているところを写真に撮られてしまった use ところを instead of ところに? Is that also because whoever took the photo did it intentionally?