How does Apple perform a lossless in-place conversion from HFS+ to APFS?
It’s a four step process according to this article from The Ecletic Light Company


Read and convert the existing HFS+ metadata (files, directories, etc) to APFS format; writes it to free space on the drive
Verifies that the APFS data is correct
If no errors, it writes the volume super block in APFS format
It deletes the HFS+ meta data leaving just the APFS volume


It converts it a single piece at a time, updating the volume as it goes.  This is why you need sufficient free space prior to the conversion process begins.