Why on some occasions is it necessary to trim horses?

  Trim horses what?

Feet-because they wear crooked or not at all.

Mane-usually only for aesthetics and to not have the mane interfere with the reins.

Tail-aesthetics-some people think they flow better and look nicer cut straight across the bottom.

Whole body-to make them easier to dry off and cool down after work during the winter months.

Teeth-because they continue to grow throughout their lifetime and wear unevenly, which could cause problems.

Those are the only things I can think that would be trimmed on a horse.
If the hoof grows to excess it can cause rotation of the pedal bone, in extreme cases the pedal bone can actually grow out the bottom of the foot and be ground away.