Kiddsmom is right about them seeing their reflection and thinking it is another bird. It tends to be the males who tink they are defending their territory from another male. (Hey their brain is about the size of a Chicklette and most of that is for sight and flying rather than 'reasoning'). If you want to stop it, tape something (newspaper, cloth etc.) on the OUTSIDE of the window so that there is no reflection for the bird to see.
It is so funny that you posted this!! We have the exact same thing happening with a female cardinal outside our downstairs window. It is ALWAYS trying to get in! My hubby thinks it a reincarnated previous owner
If it the mating season issue this bird needs to get out of this abusive relationship and find a bird that likes him. If he thinks he is fighting for his territory, he'e probably thinking man that other bird is strong.