He is doing what is called "glass surfing". The betta can see his reflection in the glass, but does not know its a reflection, he assumed its an intruder and is trying to chase it out of his territory. This is obviously not going to be successful as the 'other betta' just never seems to go away.
Some bettas get use to/over this with time but some are very agressive and never stop glass surfing.
There are a few fixes:
1:
add a lot more live/fake silk plants around the walls of the tank so teh betta can't zip along teh glass-he has to go around these plants which "breaks line fo sight" and he is more likely to forget about "the other betta"/move on.
2: a lil' DIY project involve
lexan or acrylic sheets, (recommend lexan from home depot-doesn't shatter as much as acrylic),
a cutting tool (wood blade on a saw, utility knife, etc, and
krylon fusion spray paint.
a copy and paste of one of my DIY (have done it again recently but didn't take photos when working no it. side note: measure cut, make sure it fits (put in all peices) then spray paint
DIY Anti Reflection Background
This is a GREAT fix to glass surfing bettas. Glass surfing is the act of the betta going back and forth constantly against the glass They are chasing their refection because they see it as an intruder betta and are trying to chase it off 9rather unsuccessfully). This can stress bettas because to them, they never get left alone. Some fixed include adjusting lighting and angle of light, adding more decor (fake/live plants) around the side and back wall to reduce amount of visibility and make it harder to surf the glass. But my most successful fix for it was this DIY insert made to remove reflection.
Materials Used:
Acrylic sheet
Krylon
Fusion Black
Tools Used:
Sharpie
Electric Saw
Other Material and Tool Options:
Lexan polycarbonate
Utility knife
razor blade.. just about any durable cutting tool
Photos:

Sorry no paint application photos
Details:
So one of my bettas glass surfed a lot in quarantine. TO keep it from being a problem in his final tank (and from him seeing another betta who is also on the desk in a tank next to his) I needed an aquarium safe way to paint inside the tank glass. Putting a background against the outside of it does not stop reflections. I looked into aquarium safe paints but non bound to glass. Some Googling led me to Krylon Fusion spray-paint. its commonly used in saltwater setups for DIY pvc plumbing for filters and for acrylic in tank sump boxes. More Googling said 48 seemed to be a decent cure time before use. I got acrylic sheets at my Home Depot and sanded one side to give a rough surface to let paint adhere to better. After spray painting that side I noticed the texture of the sanding showed through the paint so the acrylic was flipped over and the un-sanded side was painted. I let the acrylic sheets sit over 48 hours then did a 48 hour water test just to be safe. It turns out the un-sanded side took the pain better, and with only one coat per a side not giving a fully solid black (its transparent enough you can see dark shadows of objects behind it) it was good enough for use. A back and one side wall piece were made and tucked into the tank using 'egg crate' (a plastic light diffuser) that were being used for rocks in the tank. The beta does not glass surf the dark sides but one side wall was left un-coverd and he is glass surfing there so I will most likely make another piece to go in..
If you use Kyrlon read its directions and warnings. I strongly suggest using it outside, if done indoors without proper ventilation it can be dangerous. It was too cold to spay outside so this work was done in a room with a door to the outside nearby opened with a fan sucking the air out. If you make these sheets make sure they are secure against the tank wall. Mine are anchored under the substrate and I put a tiny piece of black tape at each corner at the top just to be safe.
I used Kryon Fusion and it seems to be the one other aquarium hobbiest use.. however I cannot say if other versions of Krylon (non 'fusion') are aquarium safe.
The tank has been set up for over a year and a half now and Aristocoles (ee betta boy in there) has had no issues with the Kyrlon...and its held up well. I'll will make 3 more Krylon fusion painted pieces for my other betta's cube and paint his canister pipes black eventually.
Added bonus: black non reflective background in tank means diatoms (aka brown algae) is not noticeable on it compared to on clear shiny glass)
As a side not: I also made a lid with the acrylic to compare with my Lexan lids... in less than 6 days it was bowed more than my over 6 month old Lexan lids.. not good lid material.. but the sheets in the tank have no bowed. I had to replace the lid with a Lexan one as the corners had turned up far enough on the acrylic that the betta could easily jump out.
most recently: 2.5g