All animals including people and fish are opportunistic feeders and take food whenever it is offered. This is a survival instinct and a normal thing to do because you never know when you will eat next. If a fish dies in an aquarium then the other fish will eat it.
If fish do eat other dead fish in the tank they can catch the disease that killed the fish so it is preferable to get any bodies out asap and do a big water change and gravel clean the substrate if you lose a fish.