Code:
$ sed '/=X /{N;N;s/\n/#/g;}' file | awk '$0 !~ /^ROUTE/{print x, $0;next}{x=$0;}' | sort -t"(" -k2n,2 | \
> sed 's/ROUTE *\([0-9]*\)\(.*\)( \([0-9]*\)\(.*\)/ROUTE \3\2( \1\4/' | \
> awk '$0 ~ x{sub(/^[^,]*,/,"");print;next}{match($0,/^[^,]*/,a);x=a[0];print;}' x="@@" | \
> sed '/ROUTE/s/,/\n/' | sed 's/#/\n/g'
ROUTE 10021
( 0001)=X 71Y 1605,
X 1486Y 2220,X 1720Y 2380,X 1962Y 2553,X 2112Y 2650,X 2289Y 2746,
YF 5000,
( 0002)=X 71Y 1605,
X 498Y 1771,X 860Y 1939,X 1036Y 2009,X 1160Y 2050,X 1292Y 2115,
YF 5000,
( 0003)=X 71Y 1605,
X 498Y 1771,X 860Y 1939,X 1036Y 2009,X 1160Y 2050,X 1292Y 2115,
YF 5000,
ROUTE 10022
( 0001)=X 71Y 1605,
X 498Y 1771,X 860Y 1939,X 1036Y 2009,X 1160Y 2050,X 1292Y 2115,
YF 5000,
( 0002)=X 71Y 1605,
X 498Y 1771,X 860Y 1939,X 1036Y 2009,X 1160Y 2050,X 1292Y 2115,
YF 5000,
( 0003)=X 71Y 1605,
X 498Y 1771,X 860Y 1939,X 1036Y 2009,X 1160Y 2050,X 1292Y 2115,
YF 5000,
ROUTE 10023
( 0001)=X 71Y 1605,
X 498Y 1771,X 860Y 1939,X 1036Y 2009,X 1160Y 2050,X 1292Y 2115,
YF 5000,
( 0002)=X 71Y 1605,
X 498Y 1771,X 860Y 1939,X 1036Y 2009,X 1160Y 2050,X 1292Y 2115,
YF 5000,
( 0003)=X 71Y 1605,
X 498Y 1771,X 860Y 1939,X 1036Y 2009,X 1160Y 2050,X 1292Y 2115,
YF 5000,