From a general Stack Exchange platform viewpoint, this is allowed but considered bad form. A questioner can accept whatever answer they prefer, including their own. It is not wrong, per se, to accept the most complete and detailed answer, even if that answer was written after seeing another answer. Moreover, there is nothing wrong with someone (the original questioner or somebody else) writing a longer and more detailed answer that reiterates information that was already posted in a correct answer but goes into greater detail. Especially on a site like Math Overflow, where precision and clarity of exposition may be particularly important, this can actually be a valuable service.
However, changing the accepted answer to one that copied a significant amount of information from the first correct answer is, while permitted, rather bad manners. Doing this robs the first person to correctly answer of acknowledgement of their correct response. I think this is especially the case when the new accepted answer was written by the questioner themself.