The robot identified itself as such in episode S02E03 "The Ghost Planet".
When asked to identify itself by the Supreme Prototype, the robot responded with his full model and assignment:
LEADER: Identify yourself.
WILL: I'm Will Robinson.
LEADER: Silence! Only the robot. The Earth creature will remain at
attention.
LEADER: Repeat. Identify yourself.
B-9: Robot, model B-9, designed and computerized as a mechanized
electronic aid for Earth voyagers engaged in astral expeditions.
LEADER: Do you know who I am?
B-9: Affirmative. The supreme prototype of all cybernetic aids.
LEADER: Correction. The supreme prototype is not an aid. He does not
obey commands. He ISSUES them.
As far as I know, this is the only time the name "B-9" was ever actually used on-screen. It quickly stuck with fans, however, and the robot has been known as B-9 ever since.
Note: Later in the same season, the robot identified itself as a Class M-3 robot. While this appears to conflict with the B-9 statement, it may not be a contradiction if the terms "class" and "model" refer to two different things. It should be noted that the response above (B-9) was when the robot was asked to identify itself as an individual. The "Class M-3 robot" response was to the question "What are you?" in episode S02E25 "The Colonists".
Update: After reviewing several interviews with cast & crew, it seems that the official "on-set" reference to the character was indeed simply "The Robot". Actor Jonathan Harris (Dr. Smith) refers to him as "the nameless idiot" in one interview, while Actor Bob May (The Robot) refers to him as "the B-9 robot" several times in his interview with KAOS 2000 Magazine in 2000.