The leaves are on the tree, because they are affixed to the ends and surfaces of the twigs and branches (as are the apples). The nest is in the tree because it is intentionally hidden by the bird within the tree's outer boundaries. It is sometimes difficult to decide which preposition to use, and no doubt some are idiomatic, but keep in mind that on means at the surface (in some way) of a 2-dimensional construct, while in means enclosed (in some way) by a 3-dimensional construct.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.