Steroids are used as treatment for acute attacks/flares in many diseases because they reduce inflammation.
In multiple sclerosis, they are given to reduce inflammation of the nerves that occurs when the immune system attacks the nervous system. This inflammation may be one mechanism that causes the nerve damage in multiple sclerosis, although this seems to still be a subject of research.
After treating the inflammation, symptoms are reduced and recovery takes less time. However, why, we don't really know yet.
It's not fully understood how steroids speed up your recovery from a relapse, but they are thought to suppress your immune system so that it no longer attacks the myelin in your central nervous system. They may also help reduce the amount of fluid around any nerve fibre damage.
Multiple Sclerosis - Treatment at the NHS website
The way that steroids work in MS is not fully understood
Multiple Sclerosis treatment (the section Treatment of Acute Relapses)
The Neurobiology of Multiple Sclerosis: Genes, Inflammation, and Neurodegeneration (summary of research into inflammation and multiple sclerosis from 2006)