For the time being, I will simply explain how capturing 2 Azelf and Uxie is possible.
First, we need to establish some key flags, map Id's and variables that will be abused.
Capture flag Azelf: 294
Capture flag Uxie: 295
Capture flag Dialga/Palkia: 351
Load flag Azelf: 510
Load flag Uxie: 511
Load flag Dialga/Palkia: 482
Spear pillar sequence variable: 16536
Hall Of Fame: 187
Spear Pillar (Box Legendarie): 220
Lake Valor (Azelf): 316
Lake Acuity (Uxie): 319
First, let's share how Azelf and Uxie their scripts work. First the game checks the 'load flag'
for them, 510 and 511 respectively. If they are cleared, then the Lake Spirits will spawn in their Maps.
After capturing them, load flags 510 and 511 are set, so they will no longer load.
Map 316 / 319
Script 3 battle Azelf/Uxie:
Script 2 Mapscript:
CheckLR0 0 func_3
With this in mind, let's explain how it is possible to capture them twice.
As you may know, if you fail capturing a Legendary and go to the Hall Of Fame,
the game gives you another shot at capturing these Legendaries. The way it does so is
by checking if the capture flag is set for that Pokémon, and if it is not, it clears the load flag.
I de-cluttered these functions for ease of understanding;
Map 187, Hall Of Fame
CheckLR 0 func_9
CheckLR 0 func_12
CheckLR 0 func_13
Setvar 16536 5
Some of you might also know that Azelf and Uxie are not accesible until after capturing the box legendary.
Not only are their areas unaccesible, they aren't loaded at all. After capturing the box legendary, the game
clears the load flags of the lake trio. But, since you aren't supposed to have battled them yet, it does not
check for the capture flags.
Map 220, Spear Pillar
Script 11 battle Dialga/Palkia:
CheckLR 1 func_25
Script 2 mapscript:
CheckLR 1 func_7
CheckLR 1 func_8
CheckLR 1 func_8
There is however one thing we are overlooking right now. In the Hall Of Fame, since we have not captured the box legendary yet, the game sets variable 16536 to 5. This variable keeps track of the sequence position of Spear Pillar, when set to 5, a trigger runs script 14 to battle the box legendary rather than 11. The two scripts are very similar, except script 14 does not jump to function 26, and does not clear the load flags of Azelf and Uxie.
So, in order to clear the flags, we will have to run script 11, which means the sequence position must be set to an earlier state.
Luckily for us, we can sequence break this position! Using the RETIRE menu, which runs script 4 in runtime (script 5 in Spear Pillar)
it runs the cutscene of the box legendary breaking free and corrupting Sinnoh.
Script 5 Major cutscene
Setvar 16536 2
Near the end of the script, the sequence position is updated to an earlier state of 2. From this point, we can trigger script 11, clear the flags of Azelf and Uxie and capture them a second time. As for Mesprit, sadly it's load flag isn't cleared using the Hall of Fame.
It is sadly not possible to just repeat the sequence position updating to an earlier state, since required NPC's are removed once the box legendary is captured. Trying to play the cutscene after that results in a crash.
If you'd like to read the entire scripts used for this rather than an abreviated version of it, you can acces Ganix's scriptdump with this link: