When finishing end grain it is important to seal it prior to applying stain. If this is not done, then it will almost certainly absorb more stain than any other part of the work piece. Depending on the species of wood and the stain color, the difference in color between long grain and end grain can be quite dramatic. I’ve seen end grain turn nearly black. Unless you going for a special effect, you generally want all surfaces to match, like the picture below.

The best sealer to use for end grain is blonde dewaxed shellac. A common product is Zinsser SealCoat. It is available at most hardware and specialty woodworking stores. This product is mixed in a 2 pound cut. It should be mixed with one part denatured alcohol to arrive at a 1 pound cut. Apply to the end grain with a natural bristle brush (a chip brush is just fine).
Being it’s alcohol based, it should dry fairly quickly. A light sanding is all that is needed before proceeding with with stain and topcoat.
This same mixture has many other uses. For instance, it can be used between incompatible finishes. Another common use is sealing blotchy woods, such as cherry, before applying finish anywhere on the board. But that is another post.
Is this necessary on all types of wood?
Every domestic species that I’ve ever worked with. You could always test on a scrap to see if it is unnecessary.