Simon Bennett, 44, admitted the manslaughter of Elliot Handley on the grounds of diminished responsibility.
Mr Handley, from Eastleigh, Hampshire, was discovered at a property in The Grove, Dorchester, on 26 May.
Appearing at Winchester Crown Court, Bennett, of The Grove, was detained under the Mental Health Act.
Post-mortem tests showed Mr Handley had suffered multiple blunt force injuries to his head.
Dorset Police said the scene was forensically examined over three days and a number of items were seized that were believed to have been used in the attack, including a claw hammer, a heavy metallic object and a bottle.
Following the sentencing on Monday, senior investigating officer Det Ch Insp Neil Devoto said: "Our thoughts today are with Elliot's family who are being supported by family liaison officers."
A man who admitted killing a 46-year-old whose body was found in a flat in Dorset has been detained indefinitely in hospital.