The CPU *shouldn't* have come off like that, but obviously it did, so what can you do?
The bent pins can be a pain, but it doesn't look too bad judging by the photo. The CPU socket itself is ZIF (zero insertion force) so ideally, with the socket in the unlocked position, the CPU should fall right into place without any pressure.
The socket will typically have a slotted dial (looks kind a plastic, flat screw head) or a lever that locks it into place. In the unlocked position, the CPU will fall in and can be removed very easily.. in the locked position, the CPU will is almost impossible to insert and tought to pull out (although it'll still come out, even if it is locked... as you may have noticed).
You should be able to pry the CPU from the heatsink. I've had to do this before and I've actually done it with a flat head screw driver... I know that sounds questionable (and it is), but you'll have to use your best judgement. I prefer to use nylon and plastic
tools when available, but I know that isn't always an option. If you can find some sort of plastic pry-bar like item, you should be able to safely remove it. The thermal compound used by manufacturers tends to harden into that plasticky material I mentioned above and occasionally it requires some force to separate it from the heatsink. You shouldn't have to strain yourself though.. it should just be a matter of leverage and firm pressure.
If you can get the two separated, clean the surfaces of both really well with some alcohol, seat the CPU into the unlocked socket, lock the socket, apply thermal compound as you like (i usually just put it on the heatsink), plop the heatsink down and affix your fan. You should be good to go.