There are many reasons to heave to, usually all related to stopping the boat to fix something that has gone wrong.
It could be that the weather has become too powerful to safely navigate, or that your gear broke and you need to stop and tend to repairs. It could also be that someone fell overboard and you need to recover them!
All of these situations involve something that is not good happening, and heaving to to let you fix it.
There is one pleasant reason to heave to: because you want to.
If you are granted a weather window to leave an inlet but are faced with an upwind destination, you could either tack forever and work like a dog; or heave to and wait for the right winds.
Heaving to will pretty much stop you in the water, making you slowly slip sideways through the sea. This means that you will move slower than if you ran, or lay a hull (which would be the equivalent of running under bare poles).
Heaving to also keeps your sails ready should you drift into something and need to get away from it. If you were laying a hull, you would need to hoist the sails and set them, whereas heaving to would only require that you set the sails.
Once the weather you want comes around, you will then scoot right along without having to work very hard. This will put you further along and makeup for the day you sat waiting still in the water.