The 20-year-old victim was trapped in a room in Marsh Way House and stabbed in the arm by John Pollard, 40.
Pollard's 19-year-old accomplice Keane Hodgen then robbed the victim of his mobile phone.
Leeds Crown Court heard the victim had been drinking and caught train from Normanton to Wakefield before getting lost on the evening of October 23 last year.
Police release images of man wanted in connection with serious assault at Wakefield pub
Video footage shows massive blaze in Ferrybridge
New coffee shop unveiled in old Genesis Barbers building in Ossett
Heartless thieves steal £600 watches from Wakefield Hospice charity shop
Angry revenge-porn boyfriend jailed for sending explicit photo of his ex
Mark Brookes, prosecuting, said Pollard spotted him near to a shop and struck up a conversation with him before offering to let him stay in his room for the night for £20.
They went to a cash machine and the victim withdrew the money and gave in to Pollard.
They went to Marsh Way House where Pollard threw a stone at an upstairs window before being buzzed into the building.
Hodgen, 19, was in the room smoking cannabis and the victim then asked for more money.
When the victim refused, Hodgen produced a kitchen knife and started sharpening it on the floor.
He tried to leave but was told he was not allowed to until he had paid more money.
Hodgen left the room and returned with Pollard before giving him the knife, saying he would leave the room for a while and telling him not to let the victim leave.
The victim grabbed his jacket and mobile phone and tried to push past Pollard.
Pollard grabbed his arm and the victim tried to defend himself but was stabbed in the forearm.
He was pushed into the shower where Hodgen demanded the pin code to unlock his mobile phone, which was worth £150.
The defendants were later arrested but the knife was never recovered.
In a statement the victim said he had been unable to return to work as a result of the injury to his hand.
Pollard was jailed for two-and-a-half years after pleading guilty to inflicting grievous bodily harm.
He also pleaded guilty to causing harassment, criminal damage and assaulting an emergency worker in relation to an incident in Living Care Pharmacy in Trinity Medical Centre in Wakefield on July 13 last year.
He threatened a customer in the pharmacy and caused £50 worth of damage when he kicked a shelf.
The defendant then lashed out at a police officer when he was arrested close by.
Pollard has six previous convictions for 12 offences, including an assault and public order offences.
Hodgen was jailed for two years after pleading guilty to robbery.
He has three previous convictions for four offences, including burglary and aggravated vehicle taking.
Anastasis Tasou, mitigating for Pollard, said his client suffers from serious psychiatric issues and had to be assessed as fit to plead before entering his guilty pleas.
Philip Morris, mitigating for Hodgen, said his client pleaded guilty to the offence at an early stage.