This is a small macro called during tpre.g and it is supposed to pause if V endstop is not triggered, but it will display the M291( which will stop and wait for OK) then it will execute tpost.g and only then will pause the print.

That's correct, if you execute M25 when a tool change is in progress, it will complete the tool change first. M25 can only pause the print at the end of executing a complete line of GCode from the file being printed.