What made the Robot switch at the last minute? (Spoilers)
Will had tried to reconnect with his robot friend several times after Dr. Smith resurrected him (it). But the robot was having none of it. So, what made it suddenly switch and save Will? That was a big moment that was unearned because it had no explanation.
What they SHOULD have done was have Will lead the robot away from his family as it followed him in order to kill him. Then, just as the Robot has Will cornered and Will realizes he is about to die, he makes one last ditch effort to communicate with the Robot; in a fogged up ship window he draws with his finger the "alien art" that the robot drew in the sand. As the Robot closes in on Will ready for the kill, it sees the symbol of its galaxy (as we find out at the end) and that symbol "reboots" the Robot. The Robot continues to move closer to Will but instead of harming him, it seals his spacesuit and saves his life, just like what eventually happened. This gives us some rationale as to why the Robot suddenly switches back to being Will's protector.