This happens to me sometimes. I constantly do transitions to keep the horse focused on me. Prevent the horse from predicting what's going to happen next. If you always go straight to the walk after cantering, maybe try trotting or even halting after your downwards transition. Maybe, to keep the horse from wanting to canter, you could do some leg yield to keep them focused on the task that you're asking for.
@fridabirkeland I made him go backwards as well, but as soon as I started to walk he tried to switch to canter again! The only thing I could do was to make him stop and wait until he calmed down... Thank you for your answer btw!
My horse used to do that (still do it sometimes). But then I made him stop, and go backwards. That worked 50/50, so I tried to just turn him around, so he couldn't go any further without going into the wall or out of the road. He still does it sometimes, but not so much.