I totally understand your dilemma. You'd think that corals were plants since they don't move around much, and they need sunlight to thrive.
But it just isn't so. They are most definitely animals. Sure, they don't seem to move much when you look at them, but neither does the average office employee.
Corals are moving around, but on a scale that we can't see very well unless we're all up in their space.
Not all corals need sunlight to live, but the tropical coral reefs we usually think about do. But even then, it's not technically the corals themselves that need sunlight, it's the photosynthetic algae (teeny tiny plants) that live inside the corals that need it.
It'd be like if you had a corn plant growing in your stomach. You'd need to expose it to sunlight for it to grow and make food for you to eat.
Corals also get food from filtering seawater and eating plankton, but the algae give them a constant supply of food and oxygen (the products of photosynthesis) so it's in the corals' best interest to grow where the algae will be happy.
This is technically a mutualistic relationship (see my post on symbiosis): the coral gets food and oxygen, and the algae get carbon dioxide and a safe place to hang out. But sometimes I wonder if the algae is being held against its will.
Corals are very sensitive to changes in water temperature, salinity (how salty), and pH (how acidic). Changes in any of these areas can really stress corals out. And when they freak out, they eject their algal guests. This is called "coral bleaching."
If the stress subsides, corals recolonize themselves with algae, but if the stress continues, the coral may die.
It seems strange that corals would eject the algae when they're stressed. It's like a person who doesn't talk to anyone when they're going through a tough time. Let your friends be here for you, coral. They can help.
Want to know more about corals? Check out oceanservice.noaa.gov