Epilepsy can be caused by a lot of different things which can affect the brain. The seizures occur because there is a disturbance in the electrical activity of the brain. People can have one-off epileptic seizures without actually having epilepsy: epilepsy is the tendency to having seizures that start in the brain.
I have a friend who had epileptic seizures, and it turned out to have been caused by a tumour in his brain. Once the tumour in his brain was removed, he stopped having seizures. You might have seen his story on the BBC, he had a brand new kind of surgery that had never been done in the UK before: http://www.bbc.co.uk/news/health-34041863
For other people, epileptic seizures can be caused because of a problem with the brain chemistry, and this can be fixed by taking special medicines to help make the brain chemistry normal again. In other cases, they can be caused by a brain injury, and might gradually stop as the person heals after the injury.
However, in over half of cases, there isn’t a cause that can be found. We need to do more research into this, to help people with epilepsy. My research might one day help, since I’m developing nanoparticles which can ferry drugs into the brain more effectively.