It happens when another player has the same number. I assume the game gives it to the player with more seniority but it could also be based on rating.
I noticed it when I had an outfielder with the Twins. I chose #2. When I got to the majors, it switched to #4 because Arraez had that number and #3 was retired. When Arraez was traded that season my player got #2.
I also noticed when I had a player with the Rockies that Jose Berrios was #18 for three seasons with them and then Kris Bryant joined the team via trade mid season and Jose switched to #20.