Possible meanings are that 1) Doeg had some religious work regarding Yahweh to do there. Alternate translation: "for some work before Yahweh" or 2) Yahweh detained Doeg there. Alternate translation: "because Yahweh had detained him there" (See: [[rc://en/ta/man/translate/figs-activepassive]])
You may need to say clearly that Doeg saw what David did. Alternate translation: "Doeg ... herdsmen, and he saw what Ahimelech did" (See: [[rc://en/ta/man/translate/figs-explicit]])