The index drop is performed in a separate WriteUnitOfWork than their recreation on the catalog (part of `MultiIndexBlock::init`):
https://github.com/mongodb/mongo/blob/5767ee2421fa6c7934a90e9083f07743a83dcf71/src/mongo/db/catalog/collection_compact.cpp#L179-L188
Note how repairDatabase's index rebuild avoids this problem: https://github.com/mongodb/mongo/blob/5767ee2421fa6c7934a90e9083f07743a83dcf71/src/mongo/db/repair_database.cpp#L146-L150
It may be reasonable to have compact re-use the repairDatabase code for this.