That's expected. Device IDs can have spaces.
The truth is that whitespace is not expected at all at the ends of the text string. That's exactly why languages like java or javascript have a method called 'trim()'.
While we wait for this observation to be considered in future versions, it is the user's responsibility to know what they are doing and to be careful not to enter such spaces by mistake.
Actually that was my Idea also, you would not expect a space at the end of the text string to be valid for a device id.
Just looking into Modern web login and noticed a device which i added did not come online.
I did copy and paste the device ID when i created the device and noticed in the log that the device was still unknown.
Then i noticed that the copied ID had a space at the end so it seems it actually saves the space also.