The simple answer is that after the mod system resets the game files to the backup state the mods are applied from top to bottom with each successive mod applying changes to the resulting state of the files.
There are some nuances to how the order affects the conflicts of mods as there are multiple ways to mod scripts. Line edits (tagged changes) to add or remove lines from existing definitions are tracked by the mod system in order to attempt to maintain correct line targeting for later mods. However, if multiple mods attempt to edit the same lines, then the mod system will likely not resolve the conflict. Due to the line targeting corrections lines added by mods are not indexed, and thus cannot be directly line edited.
For file patching and definition replacements (untagged changes) the mod system overwrites the relevant code regardless of prior changes and resets the tracking of line edits. However, this means that successive mods may incorrectly target lines if they were expecting a vanilla definition.