There are a couple of ways to interpret the series of events and how each mutant has lost their powers.
1.
They're both getting old.
At the time of Logan, Xavier is about 97 years old.
Logan's physical body is reaching about 150 years old (although depending on the timeline shenanigans he could mentally be a lot older).
Logan hasn't been kind to his body, relying on it's healing ability heavily throughout his life.
We don't know the science, but it could easily be that since he's gotten older his powers have weakened, either due to old age or the extensive use of his power.
Add on top of that the adamantium in his body poisoning him, and you've got a Wolverine that can't heal as well.
Charles, at his age, is suffering from seizures, and seems to be suffering from Alzheimer's and dementia as well.
At the time of the movie the mix of old age and mutant powers is unknown, but with Charles having a psychic ability it wouldn't be surprising if the two are hand in hand, IE his ability causing his illness 2.
They're slowly being killed by the chemicals in the food Both Charles and Logan, along with their friend, are relatively alone in the world.
It has been years since a new mutant has born, and previous events have killed off most other mutants though either mutant hunting or mass die-off events, such as Charles' seizure accident.
It was stated later in the movie that naturally born mutants stopped because of a chemical introduced into the food supply.
Since this chemical somehow suppresses the mutant gene, it wouldn't be surprising for it to have an adverse, if not long term, effect on those still living.
We don't know the chemical or how it works, or what it's long term effect is on those that are mutants that are living.
movies.stackexchange.com/users/52/DForck42
The reasons behind the loss of powers of Logan and Xavier are somwhat different: Its unsaid, but it appears clear that we are meant to assume that Xavier is beginning to suffer from some form of dementia.
The story is exploring what would happen to someone with such overwhelmingly strong powers, but who like many people start to see their mind degrade with old age.
Logan on the other hand is being poisoned by the Adamantium that was added to his skeleton.
Adamantium is a metal and although it is strong and relatively unreactive, it is slowly poisoning him - notably interfering with his healing factor.
movies.stackexchange.com/users/40/iandotkelly
From wikipedia: His healing factor has faltered and, as a result, his body has aged, he can no longer heal at an accelerated rate and his adamantium skeleton is slowly poisoning him .
Logan lives with mutant tracker Caliban in an abandoned smelting plant in Northern Mexico, where they care for former Professor Charles Xavier, who is suffering from an unknown brain disease which causes him to lose control of his telepathic abilities to destructive effect via seizures.
https://en.wikipedia.org/wiki/Logan_(film)
movies.stackexchange.com/users/None/
Original Answer 1 One of the provided answers neglects to mention that Logan is deteriorating from the metal that was injected into his bones and both answers neglected to state that Xavior's "dementia" is a product of the drugs he takes to prevent the seizures.
When he is off the drugs he does not suffer dementia.
I've seen the movie a few times though
and I do not recall any explanation given for why he has the seizures in the first place.
I like the other answer's food theory.
In response to the comment: He definitely doesn't like the effect that the drugs have on him - but do we really see proof or dialog that indicates that the drugs are what is actually causing his dementia / other symptoms?
The symptoms of dementia come and go - people have more lucid days than others.
The only real time we see symptoms of dementia in Professor X is at the beginning when he is frantically rolling around his... water tank.. thing, reciting Taco Bell commercials.
Other than that he is frail, but completely lucid throughout the movie.
Later on, in a scene where Logan is driving X and the kid away from the hotel after X intentionally 2 had a seizure, Logan was chastising X for not taking his meds.
X made it clear that he did not like the meds, saying something very close to
"I guess you prefer me mentally castrated and rambling like a lunatic."
That is literally the only reference made to the dementia in the entire movie and it was clearly blaming the drugs for the dementia symptoms.
Early on he also implied that meds put him to sleep 3 .
In the comics, X never had this condition, so there is nothing to reference as "proof.
" The only answer there is is speculation and inference.
It's not a math problem.
1. Answer or Comment 2.
X implied it was intentional, but Logan said he "just freaked out and had a seizure." 3.
He calls Logan "the man who puts me to sleep" during the one and only dementia episode he has, which is at the beginning of the movie.
movies.stackexchange.com/users/53757/I wrestled a bear once.
He wasn't.
At least not specifically his powers.
He was having seizures and losing control period .
Just like if you had a seizure and your legs lashed out.
movies.stackexchange.com/users/666/Kevin
Throughout  Logan  we see that Charles does not have the same control of his powers as he did in previous movies.  He has these seizures that keeps everyone paralyzed and harms people. He talks to himself (people that don't exist?!).  We also see that Wolverine does not have the same healing efficiency, his claws do not work as well as before.  Is this because of his aging? Does every mutant that ages start losing control of his/her powers?
Why was Xavier losing control of his powers?
movies.stackexchange.com
<character><x-men-cinematic-universe><logan>
movies.stackexchange.com/questions/76245
movies.stackexchange.com/users/42976/Gustavo Gabriel
Its unsaid, but it appears clear that we are meant to assume that Xavier is beginning to suffer from some form of dementia.  The story is exploring what would happen to someone with such overwhelmingly strong powers, but who like many people start to see their mind degrade with old age.  Xavier is shown to be suffering from some form of dementia. 
 Xavier is shown to be suffering from some form of dementia. Logan on the other hand is being poisoned by the Adamantium that was added to his skeleton. Although it is strong and relatively unreactive, it is slowly poisoning him - notably interfering with his healing factor.