One of two men accused of murdering a fellow prisoner has told a magistrate he killed the victim because he was a child sex offender.