In the first few minutes of any screenplay or film, the tone of the story causes an unconscious expectation to form in the audience’s mind as to how they should view the film. Is it serious, funny, somber, light-hearted, etc?
The opening scene of There’s Something About Mary shows a tree in front of a high school in a bucolic neighborhood. It ends by revealing two guys up in the tree playing and singing the opening soundtrack.
This oddity established the film’s broad comedic tone. It let the audience know right away not to take the film too seriously — that we’re supposed to sit back and laugh. And by establishing this tone in the opening scene, it allowed the filmmakers to get as absurd as they want to, without losing the audience.