How they work depends on what type you take. The most common ones are SSRIs selective serotonin reuptake inhibitors. Serotonin is a chemical in the brain that is primarily responsible for your mood. Lack of serotonin causes depression. Think of it as a happy hormone. SSRIs inhibit the reuptake of serotonin which causes the levels of it in the brain to increase and this gradually reduces your depressed mood.
They don't all work for everyone, there are dozens of types and they're trial and error to find the one that works for you. I don't get along with SSRIs so I take an older tricyclic antidepressant.
Tricyclic are a less refined drug, they work the same on serotonin but are less selective in the chemicals that they increase and also affect norepinephrine receptors. This means they are almost guaranteed to work but do affect more systems throughout the body which sometimes results in more side effects, it depends on the person.
They're a bit of a sledgehammer approach to depression but I find them to work well for me. I can live with the dry mouth.
Many people come off them especially in cases of situational depression where the persons circumstances change and they are happier and less stressed as a result. You don't have to stay on them forever.
The trick is to do it slowly over months to avoid shocking your brain with sudden withdrawal. You should always stay on them for a good year after your depression improves though. They're like antibiotics, stop too early and it comes back.
Over a year or two of taking them, your brain gradually becomes used to this higher level of serotonin. It becomes the norm and by ever so slowly withdrawing it, your body takes up the slack and will attempt to maintain the new normal balance of chemicals.
If you have any symptoms while trying to come off them, you should stop, increase the dose back to the last dose at which you had no symptoms and maintain for a few weeks before attempting to drop the dose again by like 5mg. A tiny amount. Its a marathon, not a sprint.
Others whose depression is recurring do choose to stay on them permanently as they feel that the impact of taking medication daily is less than the impact of living with depression. But it is totally your choice.
There's really nothing to lose by trying them. The worse you'll get is they make you feel a bit grotty for a few weeks while you adjust. If the side effects last longer you just ask to change and try another one. You won't get any withdrawal doing that, you have to be on them months and months before that would happen.
I think I went through 6 before landing on Amitriptyline and I've been on it for a good 5 or 6 years now. I'm probably going to stay on it long term tbh, I spent so many years struggling that I'm in no hurry to get off it.