替死鬼 comes from folk belief that a ghost (
鬼) who died unjustly could find a 'replacement' (
替) to die in their place and free them from the underworld. Figuratively, it now means any innocent person made to take the blame or punishment for someone else.