If you mean they should sort in the 1..22, X, Y, M order, then you can translate those X, Y, M to numbers before sorting and back after sorting:
sed 's/X/23/;s/Y/24/;s/M/25/' < file | sort -n | sed 's/23/X/;s/24/Y/;s/25/M/'
If those numbers are in a zsh array, you can apply an arbitrary sort order using this hack:
k=({1..22} X Y M) v=({01..25})
typeset -A rank=(${k:^v})
unsorted=(22 Y 5 X M 13)
sorted=(/(e'{reply=($unsorted)}'oe'{REPLY=$rank[$REPLY]}'))
Or if the members of $unsorted are unique, use array intersection:
all=({1..22} X Y M)
unsorted=(22 Y 5 X M 13)
sorted=(${all:*unsorted})