The man, 36, from London, admitted having sexual relations with a mentally ill woman after she became pregnant at the Surrey unit in 2019.
The woman was unable to care for the baby, so they were removed by children’s services after birth.
Judge Rufus Taylor, sentencing the man at Guildford Crown Court, stated that the harm he had caused was “very high.
During a hearing in June, the man pleaded guilty to the charge.
The woman’s mother, who lives in Hampshire’s New Forest, had previously raised the case with her MP over concerns about the child’s future care, who was born later in 2019.
To protect the identity of the child, none of the parties involved in Friday’s case can be named.