Carer Stephen Nicholson, of no fixed address, is accused of repeatedly stabbing the 13-year-old in the neck and upper body at Southampton Sports Centre before leaving her to die in July last year.
Richard Elmes, the partner of Lucy's mother, Stacey White, told Winchester Crown Court that he became aware that the defendant, whom he described as having been his "best friend", had been selling cannabis at the address.
He agreed when James Newton-Price QC, defending, asked him whether friends would come to the house to buy the drug from Nicholson.
The court heard that Ms White had sent a message to a friend saying that "a certain child of mine (has been) shouting I have a drug dealer in the house".
Mr Elmes said he did not remember Lucy complaining to him about Nicholson dealing drugs but added: "His cannabis was always kept upstairs in his drawer."
The witness has told the court that he asked Nicholson, who was a lodger at the family home, to leave the house because of ongoing arguments between him and Lucy.
Mr Elmes described Nicholson as being "volatile" on July 23, two days before Lucy disappeared, adding: "Which is why he was asked to leave."
Mr Elmes has also said he had arguments with his partner's daughter and admitted sending a message to Ms White saying: "I'm going to end up punching Lucy."
Ms White replied: "If you punch a child you will end up in jail so is it worth it, seriously?"
Nicholson, 25, is charged with Lucy's murder as well as three counts of rape against her when she was 12.
He also faces two charges of sexual activity with a child against Lucy on multiple occasions when she was 13.
He is also charged with sexual activity with a child in relation to another girl aged 14, dated June 29 2012.
The defendant denies the charges and the trial continues.