I've found that the error does not occur if the code creates a new PDDoc and PDPage as the target for the merge operation instead of using a target PDF. For my workflow this is an acceptable solution.
So apparently something about the state of the target PDF or its page causes the error. Possibly PDFL is getting confused somehow. The target PDF that was being used was an empty template PDF. Using PDDocRemoveStructTreeRoot(), PDDocFlattenOC() and PDPageRemoveCosContents() before beginning the merge did not affect the outcome. Merging that PDF as the first in the sequence works fine also.