I was going to make a thread on this very topic actually so I'm glad other people are seeing this issue. I was excited when I achieved a max ally status (20/20 and all the pacts etc.) with an AI and then was super annoyed when they turned hostile after the last non-ally AI was killed off. This should be fixed. If you make an alliance with someone during a game, and if allied victory is turned on, then you both should win, especially when it takes so much time and energy to get to max allegiance. There could even be some sort of final pact called "allied victory" or something that, when accepted, means that you both win when all your now mutual enemies are defeated.
The only issue would arise if there are more then two people trying to ally to the same players. Example:
A & B - Max Allegiance
A & C - Max Allegiance
B & C - Max Hatred
The only way I could see this working is if "Player A" would be forced to end their alliance with either "Player B" or "Player C" once all the other enemies are defeated. Another option is to simply have it so that if "A" and "B" are fully allied and "A" and "C" are fully allied, then "B" and "C" are automatically fully allied as well.
In the end I suppose I can see why alliances are currently the way they are. There are a lot of variables in trying to decide things like victory conditions and standings between multiple players as a game is being played and every player can have drastically different allegiance levels to one another at any given time.