This technique is called foreshadowing. It is meant to be used to drop subtle hints about what is going to happen later on in the book, the movie, the play, etc. Detective novels and movies are usually the best examples of foreshadowing because one has to realize that a clue might be significant or not in the moment, or at least have it be significant enough to stand out if it’s important. Other genres make use of foreshadowing as well, from starting with a prologue to dropping hints about things.
One good example of a novel with foreshadowing is any of the Sherlock Holmes books. They’re all told from Dr. John Watson’s point of view, so he often has a few ideas on how the pieces connect.