Because that is what you asked it to do!
When you specify a length in the scanf format string, that is what it looks at:
scanf - C++ Reference[
^]
And if you look under "whitespace":
Whitespace character: the function will read and ignore any whitespace characters encountered before the next non-whitespace character (whitespace characters include spaces, newline and tab characters -- see isspace). A single whitespace in the format string validates any quantity of whitespace characters extracted from the stream (including none).
Not the last bit (I made it bold so it's clearer)
So your format string goes:
"%2d" - OK, I need two digits... 1 and 2. Excellent!
" " - OK, I might need some whitespace - what's the next character? A digit? that'll do!
"%5d" - OK, I need five digits... 3, 4, 5...and a space. So that's the end of that number.
So when you later do the next scanf, it still has data in the buffer, and processes that.
If you want it to behave differently, you will need to read the data as a string, and break it up yourself!