This could happen in one of two ways:
1) The mind-body problem is solved first, and the solution is used to build a conscious robot.
2) The robot is built accidentally and then scientists analyse it to figure out the solution to the mind-body problem.
Mind-body Problem: Historical Background
The mind-body problem is the problem of understanding how the mind (and its conscious mental states) relate to the body (and its physical states).
Some consider mind and body to be part of one substrate—a belief known as monism, held, for example by physicalists)—but others think that mind and body are separate substances or aspects of one kind of substance (dualism).