Do you have to target a unit with Ruined Rex if he dies?
Yes, you must target an enemy unit if one is available on the board.
According to RiftJudge FAQ #10066, Deathknell triggers are mandatory. Because Ruined Rex's ability text does not contain the word "may" (e.g., "you may deal 4"), you cannot opt out of the ability.
If there is a valid enemy unit on the board, you are required to target it. If there are no valid targets on the board when the ability resolves, the ability will still trigger and enter the chain as a pending item, but it will simply do nothing.