This is not exactly a bug. In reality, the game sees two "1"s side by side, so it puts them together (even though it is a higher number).
Not exactly...
It's doing a text comparison, not an integer comparison.
That means, it sorts the entire string "TM x".
And this means, that it sorts every character in the string separately.
For this example:
2 is smaller than 3, so it puts all items that start with "TM 12" before all items that start with "TM 13".