As it stands, it is ungrammatical. As you suggest, there should be something else that connects the phrase after the comma to what precedes it.
Purely in terms of fixing the grammar, it might become:
Sometimes, when we ran out of time and did not have space for any further activity, he used to tell us that should anyone need any assistance or have any query, they should accompany me to my office.
But in terms of also fixing the meaning, it would likely be as you suggest:
Sometimes, when we ran out of time and did not have space for any further activity, he used to tell us that should anyone need any assistance or have any query, they should accompany him to his office.
It wouldn't be grammatical if the comma were replaced with a period either. Turning the portion after the comma into its own sentence would be fine grammatically, but it would sound odd. Worse, however, is that what precedes the comma is not an independent clause, and it can't stand on its own. Should anyone need or have any query needs a conclusion.
This would be acceptable as reported speech: "Should anyone need any assistance or have any query, accompany me to my office." However, it should be noted that it would still be ungrammatical. (If we don't accept [they should] as simply being elided.) Of course, conversational English often is ungrammatical. If it were done intentionally, that would be fine.
However, I would never allow this to stand as it's written. If it is supposed to be reported speech, it should be marked as such. By all norms of punctuation (and perhaps grammar, depending on how that's viewed), there would need to be some kind of explicit indication that the second part of the sentence is speech and not just narrative.