I used to use Orbx’s FTXCentral utility to re-sort scenery layers to proper sequential order. FTXCentral is good but have a number of cons.
FSTscenery by Steve Greenwood is an extremely helpful alternative if sorting Layer number sequence/priority is the only requirement. It creates a new version of scenery.CFG with all areas ordered properly. Gaps in area or layer numbers are also deleted.
The file can be downloaded from Steve’s flight-sim traveler website.