Judge Ian Mill said the risks of further emotional damage to the boy if he was returned against his wishes to his parents were too great.
Nelson MP Nick Smith was fined $5000 last month and found in contempt of court after intervening in the dispute.
He made public details of the case, and twice phoned the cousin - calls which the courts said were an attempt to pressure her to give up the child.
He has consistently said the child should be with the parents. Last night he denied there had been any violence in the home and told the Herald the parents were "devastated" that the High Court yesterday upheld the Family Court's decision to award custody to the cousin.
Dr Smith said the judgments showed that a psychiatrist's "theory" outweighed the rights of good parents.
The judgments released yesterday are the Family Court judgment last year awarding custody to the cousin, and the High Court's decision turning down the birth parents' appeal.
Both courts ruled the welfare of the child over-rode the wishes of the birth parents.
Both judgments detail ongoing learning and emotional difficulties faced by the boy, blamed on the trauma he experienced in his early years.
They show the boy's mother was the victim of physical and emotional abuse from his father and in 1998 she took out a protection order against him and asked a cousin to care for their son.
Exposure to that domestic violence in his first months was said by a psychiatrist to have left the child psychologically damaged.
"We are talking about a little boy who's had some pretty awful experiences in his early life that he hasn't yet overcome ... He is a little boy who is talking about very primitive anxiety," the psychiatrist said.
"I've never heard of a little boy who has said, 'My wishes in life are for me to live and my family not to die'. That's very early damage."
However, the Family Court offered strong praise for the boy's parents and the father who has turned his life around.
Judge Mill said the parents could now offer the boy a home in a safe, child-focused and stimulating environment.
"They are doing nothing wrong. This is one of the most remarkable turnarounds in a family I have seen. The parents are deserving because of what they have achieved."
However, the law required him to consider the welfare of the boy first. The child wanted to stay with the cousin, with whom he had now bonded, and the evidence said there was a "probability" of serious trauma if he was moved.
Although the two judgments have now been released, the law prevents the boy, his parents or the caregiver being identified. Family Court cases are usually confidential to protect children.
High Court Justices Warwick Gendall and Ellen France allowed publication of non-identifying details about the case.
The child's parents have said they asked the child to be cared for by a cousin because the mother suffered an emotional breakdown after losing another child to cot-death, and after close relatives died.
They used the protection of parliamentary privilege last year to claim the state had "stolen" their child.
Full High Court judgement