The sentence in your example is not a well formed sentence and is ambiguous but is grammatically correct. The problem is with the placement and association of one of the prepositional phrases
from behind a tree
Syntactically correct but semantically questionable.
Most readers would probably assume the detective was the person "behind a tree" (especially if there had been a "," after killed to offset the prepositional phrase), since that's what detectives do: sneak around. They also take pictures for evidence.
However, a second alternative is that the woman, acting as a sniper, shot someone while hiding "behind a tree".
A better phrasing for the first alternative might be
The detective took pictures, while hiding behind a tree, of the woman burying the body of the person she had killed.
"Watched" is implied from "took pictures", since one must "watch" in order to take pictures.
"What was going on" is understood implicitly, why else take pictures?
Better phrasing for the second alternative would be to break it up into two sentences
The woman shot someone while hiding behind a tree.
The detective took pictures of the woman burying the victim.